0

Hello all,

I'm trying to set up an add contacts page but when I click submit then check the database there is nothing there. I ran my sql query in phpMyadmin and got an error but for the life of me I cannot figure out what is wrong.

I can display the dummy data I inserted but it's the INSERT that is the issue.

Any help much appreciated.

Error
SQL query:

(

"INSERT INTO `greentech_leads` VALUES (' ', '$name', '$address', '$website', $contact_name', '$job_title', '$email', '$tel', '$notes', '$follow_up', '$greentech_contact' ) "
) OR die(
mysql_error(
)
);

MySQL said: 

#1064 - 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 '"INSERT INTO `greentech_leads` VALUES (' ', '$name', '$address', '$website', $co' at line 1 
4
Contributors
4
Replies
6
Views
5 Years
Discussion Span
Last Post by scaiferw
0

Thank you CimmerianX, believe it or not I actually looked for spaces, ticks, single quotes and commas but apparently I could not see the wood for the trees !

Works perfectly now, thanks again.

0

funny, i saw this thread earlier today and completely missed the missing single quote as well.

0

Assembling a query dynamically can be unpredictable.

When I have problems like this I usually introduce a new line to assemble the SQL statement in a variable, then print the variable to screen to let me see what I'm sending to the db server.

$sql = "SELECT $myval1,".function('foo').",myval2 FROM mytable;";
echo "<p>$sql</p>"; // temporary debug line 
$result = mysql_query("$sql");

or

$sql = "SELECT $myval1,".function('foo').",myval2 FROM mytable;";
exit("<p>$sql</p>"); // temporary debug line 
$result = mysql_query("$sql");

Then I eyeball the SQL statement that I've output with the echo or exit statement and usually run it with a query tool like HeidiSQL. Once I get the query working in HeidiSQL or whatever query tool I'm using, I work my .php code to get the proper query output and then delete or comment out my echo/exit() line.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.