Cannot send text input to database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
raydona
Forum Newbie
Posts: 21
Joined: Sat Mar 21, 2009 9:17 am

Cannot send text input to database

Post by raydona »

Hi, I’ve written the following code.
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.
:roll:
tech603
Forum Commoner
Posts: 84
Joined: Thu Mar 19, 2009 12:27 am

Re: Cannot send text input to database

Post by tech603 »

$sql="INSERT INTO table (name, occupation, email) VALUES ('$name', ‘$occupation’,'$email')";
Is your table name really table? If not then you need to replace that with the table name. If your table name is table can we see the structure of your table so we can further assist you.

hope that helps

Matthew Vass
QA Anylist
mvass@hostmysite.com
http://www.hostmysite.com?utm_source=bb
Post Reply