Hi I do not understand why this code is not inserting the data from the html text feilds into my actually database. I am trying to sample it using just First_Name to start with.
Anyways HTML code is as followed :
<form action="Proform.php" name="Myform" method="post">
<input type ="hidden" value="1" name="check_submit" />
Please Enter First Name: <input type ="text" name="First_Name" /> <br />
Please Enter Second Name: <input type ="text" name="Second_Name" /><br />
Please Enter Email Address: <input type ="text" name="Email_Address" /><br />
Please Enter A Password: <input type="password" name="Password" /><br />
<input type ="submit" name"Submit" /><br />
</form>
And php and MYSQL is as followed :
<?php
$dbname='ecig';
$dbhost='localhost';
$dbpass='password';
$dbuser='eciguser';
$dbhandle = mysql_connect($dbhost, $dbuser, $dbpass)
or die("Unable to connect to MySQL");
echo "Connected to MySQL<br>";
$selected = mysql_select_db("ecig",$dbhandle)
or die("Could not select examples");
$res=mysql_query("INSERT INTO Persons (First_Name, Second_Name) VALUES ('$_POST[First_Name]')");
if (array_key_exists ('check_submit', $_POST ))
echo "Your Name is : {$_POST['First_Name']}<br />";
echo "Your Second Name is : {$_POST['Second_Name']}<br />";
echo "Your Email Address is : {$_POST['Email_Address']}<br />";
echo "Your Password Is : {$_POST['Password']}<br />";
?>
It must have something to do with this line of code but I cannot spot it.. Can any of you spot what is going wrong?
$res=mysql_query("INSERT INTO Persons (First_Name, Second_Name) VALUES ('$_POST[First_Name]')");
Any help would be much appreciated. Thanks .
mysql_*functions to write new code. They are no longer maintained and the community has begun the deprecation process. See the red box? Instead you should learn about prepared statements and use either PDO or MySQLi. If you pick PDO here is a good tutorial.