Pls i dont relly want to understand what is really wrong with the code below!
I want to insert record into the database i have written one and it is working well for two record but for these is not working. And more so it work anytime it like it there anything that i am doing wrong cos sometime one record may be blank and the other fill in or vise versa
I collect the data from a form

<table width="100%" border="0" cellpadding="0" cellspacing="0">
      <!--DWLayoutTable-->
      
      <tr>
        <td width="3" height="1"></td>
          <td width="184"></td>
          <td width="336" rowspan="11" valign="top"><form id="form1" name="form1" method="post" action="reg_forminsert.php">
              <input type="text" name="Username" />
              <br />
              <input type="text" name="Password" />
              <br />
              <input type="text" name="Confirmpass" />
              <br />
              <input type="text" name="Name" />
              <br />
              <input type="text" name="Comment" />
              <input type="submit" name="Submit" value="Submit" />
              <br />
          </form></td>
        </tr>
      <tr>
        <td height="19"></td>
          <td valign="top">Username</td>
        </tr>
      <tr>
        <td height="4"></td>
          <td></td>
        </tr>
      
      <tr>
        <td height="19"></td>
          <td valign="top">Password</td>
        </tr>
      <tr>
        <td height="4"></td>
          <td></td>
        </tr>
      
      
      
      <tr>
        <td height="19"></td>
          <td valign="top">Confirm Password </td>
        </tr>
      <tr>
        <td height="4"></td>
          <td></td>
        </tr>
      
      
      
      
      
      
      
      <tr>
        <td height="19"></td>
          <td valign="top">Name</td>
        </tr>
      <tr>
        <td height="2"></td>
          <td></td>
        </tr>
      
      <tr>
        <td height="19"></td>
          <td valign="top">Comment</td>
        </tr>
      <tr>
        <td height="2"></td>
          <td></td>
        </tr>
      
      <tr>
        <td height="44"></td>
          <td></td>
          <td></td>
        </tr>
      
      
      
    </table>

reg_forminser.php

$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("forum", $con);
echo "connection successful";

mysql_query("INSERT INTO 'forum'.'reg_info' (Username,Password,Comfirm_pass,Name,Comment) 
VALUES ('$Username', '$Password', '$Confirmpass', '$Name', '$Comment')");

echo "Record Inserted";
mysql_close($con);

HI. I don't know if this will help you but here is how I have inserted similar info to a database:

mysql_query("INSERT INTO 'forum'.'reg_info'  (Username, Password, Comfirm_pass, Name, Comment) VALUES ('$_POST[Username]', '$_POST[Password]', '$_POST[Confirm_pass]', '$_POST[Name]', '$_POST[Comment]')")

Otherwise I think you would have to specify what the definitions are.
EG.

$Username = $_POST[Username];
$Password = $_POST[Password];
$Confirmpass = $_POST[Confirm_pass];
$Name = $_POST[Name];
$Comment = $_POST[Comment];

This would have to be before the SQL query.

I hope that this may be of some help. There probably more knowledgeable people on the forum, but at least I tried.

HI. I don't know if this will help you but here is how I have inserted similar info to a database:

mysql_query("INSERT INTO 'forum'.'reg_info'  (Username, Password, Comfirm_pass, Name, Comment) VALUES ('$_POST[Username]', '$_POST[Password]', '$_POST[Confirm_pass]', '$_POST[Name]', '$_POST[Comment]')")

Otherwise I think you would have to specify what the definitions are.
EG.

$Username = $_POST[Username];
$Password = $_POST[Password];
$Confirmpass = $_POST[Confirm_pass];
$Name = $_POST[Name];
$Comment = $_POST[Comment];

This would have to be before the SQL query.

I hope that this may be of some help. There probably more knowledgeable people on the forum, but at least I tried.

Thank you very much for the reply but really i tried code you gave me yet is having no reflect on the database and i really have to work on my project cos time is runing out pls if you could know any way of helping me out i will really appreciate it.

Most problems with inserts have to do with the use of quotes in queries and datatypes. Do any of the fields in the query have a numeric datatype? If so, they will not require a single quote around them in the query.

HI again. I copied your files and tested them. I have got the following PHP code to work for me. This would be saved as: reg_forminsert.php

<?

  $server	= "localhost";       // the database location (usually this will be localhost)
  $dbusername	= "root";	// the database user with all rights to the database
  $dbpassword	= "";		// the database password to the above user
  $db_name	= "forums";         // the name of the database

$con = @mysql_connect($server,$dbusername,$dbpassword) or die(mysql_error());

$table_name = "reg_info";

if (!$con)
{
die('Could not connect: ' . mysql_error());
}

echo "connection successful<br />";

$db = @mysql_select_db($db_name,$con) or die(mysql_error());

$sql = "INSERT INTO $table_name  (Username, Password, Comfirm_pass, Name, Comment) VALUES ('$_POST[Username]', '$_POST[Password]', '$_POST[Confirmpass]', '$_POST[Name]', '$_POST[Comment]')";

$result = @mysql_query($sql,$con)or die(mysql_error());

echo "Record Inserted<br />";
mysql_close($con); 

?>

I hope this will help you. There may be better ways of doing this but this is how I have been doing it for my projects.

This article has been dead for over six months. Start a new discussion instead.