When I run this query in PHPMyAdmin it works fine:

$sql = "INSERT INTO Taskers (Taskers.MemberID, Taskers.EventID) VALUES ($memberid, $eventid)";

...but when I run it from the PHP page using the $sql command, I get the error:

You have an error in your SQL syntax.....near ')' at line 2

The Taskers table uses foreign keys to relate to the primary keys in the Members and Events tables. The Taskers table also has the primary key TaskerID. which auto-increments.

I double checked: both $memberid and $eventid are set to integers.

I looked at the general log and, strangely, the query is not showing up. Running a quick test, it seems that only SELECT queries are showing up in the general log, but no DROP or INSERT commands are showing up.

closed as off-topic by ypercubeᵀᴹ, Paul White, Max Vernon, RolandoMySQLDBA, Philᵀᴹ Aug 6 '14 at 1:02

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Too localized - this could be because your code has a typo, basic error, or is not relevant to most of our audience. Consider revising your question so that it appeals to a broader audience. As it stands, the question is unlikely to help other users (regarding typo questions, see this meta question for background)." – Paul White, Max Vernon, RolandoMySQLDBA, Philᵀᴹ
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Stop, and research SQL injection vulnerabilities. You should never concatenate your variables into queries like this. There are massive potential security holes waiting for you. Even if the values come from a safe place now, that's not a good reason to build queries this way. xkcd.com/327 – Michael - sqlbot Jul 23 '14 at 1:27

GOT IT! I had to explicitly set my PHP variable types to integer after normalizing them from the Http POST function...

settype($foo, "integer");

...and then use them in the MySQL query.


Maybe this:

$sql = "INSERT INTO Taskers (Taskers.MemberID, Taskers.EventID) VALUES (".$memberid.",".$eventid.")";
  • Thanks for the suggestion, this time I received error "Data truncated for column 'MemberID' at row 1". – Justin Jul 23 '14 at 3:52

Not the answer you're looking for? Browse other questions tagged or ask your own question.