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
Share on other sites

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.