connecting to a database via a form.

  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

How would i go about connecting to a database via a form?

Would it be something like this:

Code: [ Select ]
<form name=sql method=post action=sql><table width=90% border=0 align=center cellpadding=0 cellspacing=0 bordercolor=#333333 bgcolor=#fefefe>
       <strong>Sql Details</strong></p>
      <table width=95% height=126 border=1 align=center cellpadding=0 cellspacing=0 bordercolor=#000000 bgcolor=cecece>
       <tr>
        <td width=46%>Sql Username</td>
        <td width=54%>
          <input type=text value=$sqluser>
         </form></td>
       </tr>
       <tr>
        <td width=46%>Sql Password</td>
        <td><form name=sql method=post action=install.php>
          <input type=text value=$sqlpass>
         </form></td>
       </tr>
       <tr>
        <td width=46%><p>Hostname (usually &quot;localhost&quot;).</p></td>
        <td><form name=sql method=post action=install.php>
          <input type=text value=$sqlhost>
         </form></td>
       </tr>
       <tr>
        <td height=28>Database name</td>
        <td><form name=sql method=post action=install.php>
          <input type=text value=$sqldatabase>
         </form></td>
       </tr>
      </table>
  1. <form name=sql method=post action=sql><table width=90% border=0 align=center cellpadding=0 cellspacing=0 bordercolor=#333333 bgcolor=#fefefe>
  2.        <strong>Sql Details</strong></p>
  3.       <table width=95% height=126 border=1 align=center cellpadding=0 cellspacing=0 bordercolor=#000000 bgcolor=cecece>
  4.        <tr>
  5.         <td width=46%>Sql Username</td>
  6.         <td width=54%>
  7.           <input type=text value=$sqluser>
  8.          </form></td>
  9.        </tr>
  10.        <tr>
  11.         <td width=46%>Sql Password</td>
  12.         <td><form name=sql method=post action=install.php>
  13.           <input type=text value=$sqlpass>
  14.          </form></td>
  15.        </tr>
  16.        <tr>
  17.         <td width=46%><p>Hostname (usually &quot;localhost&quot;).</p></td>
  18.         <td><form name=sql method=post action=install.php>
  19.           <input type=text value=$sqlhost>
  20.          </form></td>
  21.        </tr>
  22.        <tr>
  23.         <td height=28>Database name</td>
  24.         <td><form name=sql method=post action=install.php>
  25.           <input type=text value=$sqldatabase>
  26.          </form></td>
  27.        </tr>
  28.       </table>


and then make that go to:

PHP Code: [ Select ]
 
 
 
$sql = "
 
$location = "sqlhost";
 
   $username = "sqluser";
 
   $password = "sqlpass";
 
   $database = "sqldbase";
 
   $conn = mysql_connect("$location","$username","$password");
 
 
 
   if (!$conn) die ("Could not connect MySQL");
 
   mysql_select_db($database,$conn) or die ("Could not open database")";
 
 
  1.  
  2.  
  3.  
  4. $sql = "
  5.  
  6. $location = "sqlhost";
  7.  
  8.    $username = "sqluser";
  9.  
  10.    $password = "sqlpass";
  11.  
  12.    $database = "sqldbase";
  13.  
  14.    $conn = mysql_connect("$location","$username","$password");
  15.  
  16.  
  17.  
  18.    if (!$conn) die ("Could not connect MySQL");
  19.  
  20.    mysql_select_db($database,$conn) or die ("Could not open database")";
  21.  
  22.  


Please reply, kind of urgent. i want to make sure that im getting the idea before i carry on.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

Yea, your sorta getting it, except you dont need to start the form for each field, and you need to name all of the fields.
Also on the install.php page. you need to have
PHP Code: [ Select ]
$location = $_POST['sqlhost'];
etc.
Then I'm guessing you are going to write that to a file.
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

what you mean by i dont need to start the form by each field?
  • Scorpius
  • Proficient
  • Proficient
  • User avatar
  • Posts: 401
  • Loc: Scorpion Hole

Post 3+ Months Ago

You have
PHP Code: [ Select ]
<form name=sql method=post action=install.php>
and
PHP Code: [ Select ]
</form>
multiple times and you only need it once.
  • Nem
  • Guru
  • Guru
  • Nem
  • Posts: 1243
  • Loc: UK

Post 3+ Months Ago

yeah i got that because i was copying pasting it with the <input type="text"> :P

accidently :$

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 159 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.