Jump to content


Photo

*Solved* inserting error


  • Please log in to reply
3 replies to this topic

#1 kalivos

kalivos
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationCalifornia

Posted 20 October 2006 - 03:27 AM

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

PHP
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());

Returned
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

Database table personal_data:
fname
lname
email
character
sex
bday

Anyone see anything?
Make a donation to phpfreaks. They need your help![br][br]

#2 btherl

btherl
  • Staff Alumni
  • Advanced Member
  • 3,893 posts
  • LocationAustralia

Posted 20 October 2006 - 03:50 AM

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

#3 Skatecrazy1

Skatecrazy1
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts
  • LocationSouthern California

Posted 20 October 2006 - 03:53 AM

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.
fuck it or fight it

#4 kalivos

kalivos
  • Members
  • PipPipPip
  • Advanced Member
  • 88 posts
  • LocationCalifornia

Posted 21 October 2006 - 02:08 AM

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.
Make a donation to phpfreaks. They need your help![br][br]




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users