PDA

View Full Version : I need a new set of eyes to check this error



redeye
05-29-2006, 09:23 PM
I've rewritten my insert function with and without mysql_real_escape_string's
and I still get the same error. Can someone look it over for me? I think it has to do with with the "INSERT INTO table set..." portion of it. I'm referencing the table with $table_select.

Thanks in advance!

The error message
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 ''blank' set first_name='fff', mi='d', last_name='dfdf', suffix='Sr', ' at line 1

------
The code
$query = sprintf("INSERT INTO '%s' set
first_name='%s',
mi='%s',
last_name='%s',
suffix='%s',
address1='%s',
address2='%s',
city='%s',
state='%s',
zip5='%s',
zip4='%s',
state='%s',
phone_ac='%s',
phone_ex='%s',
phone_sub='%s',
email='%s',
bio='%s',
council_num='%s',
date_created='%s'
date_updated='%s'",
mysql_real_escape_string($table_select),
mysql_real_escape_string($first_name),
mysql_real_escape_string($mi),
mysql_real_escape_string($last_name),
mysql_real_escape_string($suffix),
mysql_real_escape_string($address1),
mysql_real_escape_string($address2),
mysql_real_escape_string($city),
mysql_real_escape_string($state),
mysql_real_escape_string($zip5),
mysql_real_escape_string($zip4),
mysql_real_escape_string($state),
mysql_real_escape_string($phone_ac),
mysql_real_escape_string($phone_ex),
mysql_real_escape_string($phone_sub),
mysql_real_escape_string($email),
mysql_real_escape_string($bio),
mysql_real_escape_string($council_num),
mysql_real_escape_string($date),
mysql_real_escape_string($date));

$result=mysql_query($query);

areidmtm
05-29-2006, 09:41 PM
Try something like this


$query = "INSERT INTO " . $table_select . "
(first_name, mi, last_name, suffix, address1, address2, city, state, zip5, zip4, state, phone_ac, phone_ex, phone_sub, email, bio, council_num, date_created, date_updated)
VALUES
('" . $first_name . "', '" . $mi . "', '" . $last_name . "', '" . $suffix . "', '" . $address1 . "', '" . $address2 . "', '" . $city . "', '" . $state . "', '" . $zip5 . "', '" . $zip4 . "', '" . $state . "', '" . $phone_ac . "', '" . $phone_ex . "', '" . $phone_sub . "', '" . $email . "', '" . $bio . "', '" . $council_num . "', '" . $date . "', '" . $date . "');";
$result=mysql_query($query);

page1ink.
05-30-2006, 09:42 AM
I think your syntax error was in using apostophes to surround your field names. MySQL interprets anything surrounded by ' ' as a value and anything surrounded by ` ` (backticks, your tilde key) as a field. alternatively, you can simply not surround field names with anything at all.
when I first started using MySQL I had that error and it was making me pull my hair out hehe =) hope you get it working!