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 

You are missing an opening ' right in front of $contact_name

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.

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

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.