Jump to content

inserting variables into table


stikky

Recommended Posts

hello, i am a complete beginner and I have been having trouble getting variables taken from a form into a mySQL table.
Yesterday, I only either got the variable names inserted (eg $fg), or I got a 'syntax error' message.
Today I extracted the values first, but no matter what I try I still get this error message:
Query failed: 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 ''test1','test2','test3','test3','test4','test5','test7','test8','test9') VALUES ' at line 1

This is an improvement, as these are the correct values (the fieldnames are also in variables).

Here is the code as it is now:

extract($customer);
extract($labels);
$sql = "INSERT INTO testing ('$firstName','$lastName','$company','$street','$city','$county','$phone','$email','$query') VALUES ('$fN','$lN','$cp','$stt','$cy','$coy','$ph','$el','$qu');";
$result = mysql_query($sql,$dbh) or die("Query failed: ".mysql_error());

$customer is the array of values, $labels is the array of fieldnames.
I have tried every variation on the theme I can think of. Please can someone help?
Link to comment
https://forums.phpfreaks.com/topic/19388-inserting-variables-into-table/
Share on other sites

Archived

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

×
×
  • 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.