First is the HTML code which creates an online form with three text fields to be filled in by the user: Name, Occupation and Email Address.
<html>
<body>
<FORM ACTION="some.php" METHOD="POST" NAME="some.html">
<TABLE>
<TR>
<TD><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Your Name:</font></TD>
<TD> <input type=text name="name"></TD>
</TR>
<TR>
<TD><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Your Occupation:</font></TD>
<TD> <input type=text name="occupation"></TD>
</TR>
<TR>
<TD><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Email Address:</font></TD>
<TD><input type=text name="email"></TD>
</TR>
<TR>
<TD><input type="submit" value="Submit" name="Submit"></TD>
<TD><input type="reset" value="Reset" name="Reset"></TD>
</TR>
</TABLE>
</FORM>
</body>
</html>
Here is the PHP scipt which will take the data input from HTML file and send it to MySQL database.
<html>
<body>
<?php
$con = mysql_connect("some.net","Username","Password");
if (!$con)
{ die('Could not connect: ' . mysql_error());
}
mysql_select_db("DatabaseName", $con);
$name=mysql_real_escape_string($_POST['name']);
$occupation=mysql_real_escape_string($_POST['occupation']);
$email=mysql_real_escape_string($_POST['email']);
$sql="INSERT INTO table (name, occupation, email) VALUES ('$name', ‘$occupation’,'$email')";
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
echo "Form data successfully added.";
mysql_close($con);
?>
</body>
</html>
I get the following error:
Error: Unknown column 'name' in 'field list'
I do not know what is generating the error, especially as database contains table with respective fields name, occupation and email where the form data will be saved. I wonder if anyone can throw some light on the error. I would be very grateful.