Mysql update issue!
Posted: Wed May 18, 2011 6:45 pm
Here I am again, members of the php technorati, with another strange issue. This time it is my update script. Here is the code:
Now, what seems to be occurring is this:
1- it skips the 2nd response update!??
2-it takes the third response and places it in the 2nd response field in the database?
***Really screws up my questionaire form!***
What the on earth is going on?!!
Does !empty cause this phenomenon ? Some one please enlighten me as to the error of my ways.
Thanks in advance,
Batoe
Code: Select all
if (!empty($_POST['submit_1']))
{
$candidateID = $_POST['candidateID'];
require 'open_db.php';
for ($i = 1; $i <= 16; $i++) {
$word = 'resp_';
$value = $word.$i;
$response = filter_input(INPUT_POST, $value, FILTER_SANITIZE_STRING, FILTER_FLAG_NO_ENCODE_QUOTES);
if (!empty($response)) {
mysql_query("UPDATE prelim_db SET $value = '" . mysql_real_escape_string($response) . "'
WHERE candidateID = '". mysql_real_escape_string($candidateID) . "' ") or die('Query failed: ' . mysql_error());
}
}
mysql_query("UPDATE prelim_db SET q_count = q_count + 1 WHERE candidateID = '$candidateID'")or die('Query failed: ' . mysql_error());
$prelim_db = mysql_query("SELECT * FROM prelim_db WHERE candidateID = '$candidateID'")
or die(mysql_error());
$row4 = mysql_fetch_array( $prelim_db );
}
mysql_close();1- it skips the 2nd response update!??
2-it takes the third response and places it in the 2nd response field in the database?
***Really screws up my questionaire form!***
What the on earth is going on?!!
Does !empty cause this phenomenon ? Some one please enlighten me as to the error of my ways.
Thanks in advance,
Batoe