0
When doing a simple insert into an MYSQL database, I get this error

"Unknown column 'Af452OtQa' in 'field list'"

'Af452OtQa' is the value that I'm attempting to insert into the column 'serialnum' All the variables are set from POST values from the previous page, and all are urlencoded except for this field, which I create the value for and thus, know that it won't have anything but alphanumerics in it.

      $insertSQL = sprintf("INSERT INTO Presentations ('serialnum', 'docurl', 'tracker', 'recipient', 'last_accessed') VALUES (%s, %s, %s, %s, %s,)",
  $sn,$doc,$trackr,$recip,$lastacc);
1
  • 1
    you forgot the quotes, he consider your value to be a column Commented Feb 20, 2012 at 20:59

1 Answer 1

2

Isn't there an extra comma in your SQL statement?

You need quotes in the values clause, not the column names portion of the insert

$insertSQL = sprintf("INSERT INTO Presentations "+
                               "(serialnum, docurl, tracker, recipient, last_accessed) "+
                               "VALUES ('%s', '%s', '%s', '%s', '%s')",
                                $sn,$doc,$trackr,$recip,$lastacc);

Also: Have you thought about using the bind variables, because your code is vulnerable to SQL Injection attacks.

Sign up to request clarification or add additional context in comments.

1 Comment

I'm not sure how to do that. I thought that's what using the %s variables did.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.