OK, this simple little query is kicking my butt. What am I doing wrong here?
$format = "'%s','%s','%s','%s','%s'";
$insertSQL = sprintf("INSERT INTO `Presentations` (serialnum, docurl, tracker, recipient, last_accessed) VALUES (". $format,$sn,$doc,$trackr,$recip,$lastacc ."')");
I realize there is an extra single quote near the end there, but I echoed $insertSQL and it gets cut off if I don’t add it. Here’s what the echo looks like, with the error message that accompanies it:
INSERT INTO `Presentations` (serialnum, docurl, tracker, recipient, last_accessed)
VALUES ('VT6Smic28','http%3A%2F%2Fgoogle.com%2Fdocs%2Fadoc.html','greg.mcgee%40advetel.com','gregmcgee%40yahoo.com','Tue%2C+21+Feb+2012+09%3A57%3A51+CST')
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 ''' at line 1
Without the additional single quote, I get a similar error message, except that it says it is near ” at line 1.
You have a trailing
'right before the final close parentheses ("')"). Doesn’t matter what you echoed; why should that be there if$formatis what you’re really putting into the query?Answer:
$formatisn’t what you’re inserting into the SQL. You meant to usesprintfon it first, but haven’t.