Jump to content

Archived

This topic is now archived and is closed to further replies.

kalivos

*Solved* inserting error

Recommended Posts

I'm having a problem inserting some data into a database. I'm getting tired and could use an extra set of eyes.

PHP
[code]
require_once("connect.php"); //db connection script

$data = "INSERT INTO personal_data (fname, lname, email, character, sex, bday) VALUES ('$fname', '$lname', '$email', '$cname', '$sex', '$bdate')";

echo $data;

mysql_query($data) or die(mysql_error());[/code]

Returned
[code]INSERT INTO personal_data (fname, lname, email, character, sex, bday) VALUES ('Tim', 'Withers', '********@gmail.com', 'numair', 'male', '199433')

You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'character, sex, bday) VALUES ('Tim', 'Withers', '********@gma[/code]

Database table personal_data:
fname
lname
email
character
sex
bday

Anyone see anything?

Share this post


Link to post
Share on other sites
Is character a reserved word?  I forget how to quote reserved words in mysql, but that's my best guess.  The syntax looks fine.

Share this post


Link to post
Share on other sites
as far as I can see, there are no errors in your syntax... that truly is a weird error... all I would say is check your connect.php file, use `'s around your field names (for example INSERT INTO personal_data (`fname`, `lname`, `email`, `character`, `sex`, `bday`)), and to also make sure you reference your connection in the mysql query (if your connection is in a variable, reference it as mysql_query($sql, $connection))

and if it's not in a variable, also make sure to close your connection at the end.

Share this post


Link to post
Share on other sites
I changed the cell "character" into char_name. **POOF** it works. Guess I was a little more tired that what I originally thought :) Thanks for the help.

Share this post


Link to post
Share on other sites

×

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.