Hello,
I am not sure what is wrong but the message from the post is successful but fields in table are empty. Here is a short version of the script:
If i hardcode the values in as in the line with //$sql = 'INSERT INTO ...' then the field is not empty.
----myinsert.php----
<HTML>
<HEAD><TITLE> </TITLE></HEAD><BODY>
<?PHP
$connection=mysql_connect("localhost","root","password" or die('Could not connect to the database server');
$db = mysql_select_db("mytestdb", $connection) or die ("Unable to select database."
$sql = "INSERT INTO userdb1 (fname,lname) VALUES ('$fname', '$lname')";
//$sql = 'INSERT INTO `userdb1` (`fname`, `lname`) VALUES (\'user1f\', \'user1l\');';
$sql_result = mysql_query($sql,$connection) or die ('Could not insert data');
echo('Data inserted successfully.');
mysql_close($connection);
?>
</BODY>
</HTML>
-----myinsert.html-----
<HTML>
<HEAD><TITLE>INSERT Data via PHP</TITLE></HEAD><BODY>
<FORM action="myinsert.php" method="post">
First Name: <input type="text" name="fname"><BR>
Last Name: <input type="text" name="lname"><BR>
<input type="submit" value="Submit to myinsert.php">
</FORM>
</BODY>
</HTML>
Could someone please tell me why the fields are empty when I post via the form, is there something wrong with my file(s)?
Many thanks.
I am not sure what is wrong but the message from the post is successful but fields in table are empty. Here is a short version of the script:
If i hardcode the values in as in the line with //$sql = 'INSERT INTO ...' then the field is not empty.
----myinsert.php----
<HTML>
<HEAD><TITLE> </TITLE></HEAD><BODY>
<?PHP
$connection=mysql_connect("localhost","root","password" or die('Could not connect to the database server');
$db = mysql_select_db("mytestdb", $connection) or die ("Unable to select database."
$sql = "INSERT INTO userdb1 (fname,lname) VALUES ('$fname', '$lname')";
//$sql = 'INSERT INTO `userdb1` (`fname`, `lname`) VALUES (\'user1f\', \'user1l\');';
$sql_result = mysql_query($sql,$connection) or die ('Could not insert data');
echo('Data inserted successfully.');
mysql_close($connection);
?>
</BODY>
</HTML>
-----myinsert.html-----
<HTML>
<HEAD><TITLE>INSERT Data via PHP</TITLE></HEAD><BODY>
<FORM action="myinsert.php" method="post">
First Name: <input type="text" name="fname"><BR>
Last Name: <input type="text" name="lname"><BR>
<input type="submit" value="Submit to myinsert.php">
</FORM>
</BODY>
</HTML>
Could someone please tell me why the fields are empty when I post via the form, is there something wrong with my file(s)?
Many thanks.