Jump to content

Recommended Posts

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.

:o

 

--USE CODE TAGS NEXT TIME... fenway

Link to comment
https://forums.phpfreaks.com/topic/150465-cannot-upload-text-input-to-database/
Share on other sites

One thing I can see right off is that you have wrong kind of quoted around '$occupation' in your query.

 

Change

die('Error: ' . mysql_error()); 

to

 

die('Error: ' . mysql_error() . " $sql"); 

and we will see how the query looks like.

 

[edit]

 

One more thing. MySQL is case sensitive when it comes to field names, so if the field's called 'Name' and you try to insert into 'name' then it will cause this error

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.