single quote error!
Posted: Mon May 02, 2011 7:20 pm
Greetings again, PHP Technorati! Ok, this is a common noob problem. I am trying to add responses to a database, but my script causes a mysql error when someone tries to upload data with an apostrophe. Mysql reads it as an extra quote that ends the query! who do I allow single quotes/apostrophes to be added to the database. Here is the code:
I searched it on the web and there is some mention of mysql real escape string! Please enlighten me as to how to solve this problem!
Thanks in advance,
Batoe
Code: Select all
for ($i = 1; $i <= 15; $i++) {
$response = filter_input(INPUT_POST, 'resp_' . $i, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
if (!empty($response)) {
mysql_query("UPDATE prelim_db SET resp_$i = '$response' WHERE candidateID = '$candidateID'") or die('Query failed: ' . mysql_error());
}
}
Thanks in advance,
Batoe