We're a community of 1076K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,075,965 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

MySQL won't INSERT

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
1 Month
Discussion Span
9 Months Ago
Last Updated
5
Views
cubalibras
Newbie Poster
9 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

CimmerianX
Posting Pro in Training
499 posts since Jul 2010
Reputation Points: 49
Solved Threads: 59
Skill Endorsements: 10

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.

cubalibras
Newbie Poster
9 posts since Jan 2011
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

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

JorgeM
Industrious Poster
4,017 posts since Dec 2011
Reputation Points: 294
Solved Threads: 546
Skill Endorsements: 115

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.

scaiferw
Junior Poster
115 posts since May 2010
Reputation Points: 25
Solved Threads: 7
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0734 seconds using 2.71MB