Is there any problem with my query?
开发者_如何学编程mysql_query("INSERT INTO questions (question_no)
VALUES ('" . mysql_real_escape_string($i) . "')
WHERE question_text LIKE ('" . mysql_real_escape_string($val) . "')")
or die('Error, insert query failed');
I'm getting the "Error, insert query failed" :(
You cannot use WHERE
clause in INSERT
.
What did you want to achieve with your WHERE
clause?
Update:
If you want to update an existing record, use this:
UPDATE questions
SET question_no = 'mysql_real_escape_string($i)'
WHERE question_text LIKE 'mysql_real_escape_string($val)'
( quote the query for PHP appropriately, of course )
mysql_query("insert into questions (question_no) VALUES ('" . mysql_real_escape_string($i) . "') ")or die('Error, insert query failed');
no need to add where clause in insert query.
Or use update query to make change in existing records
mysql_query("updat questions set question_no = '" . mysql_real_escape_string($i) . "' where question_text like '" . mysql_real_escape_string($val) . "' ")or die('Error, update query failed');
You should change it to:
mysql_query("insert into questions (question_no)
VALUES ('" . mysql_real_escape_string($i) . "') ")
or die('Error, insert query failed');
Note, that where clause in insert values statement is senseless.
Take a look at mysql doc regarding inserting a rows. Construction You were trying to use is invalid.
精彩评论