Mysql update issue!

by 7 replies
8
Here I am again, members of the php technorati, with another strange issue. This time it is my update script. Here is the code:
Syntax: [ Download ] [ Hide ] [ Select ] [ Expand ]
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();


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 on earth is going on?!!:confused:
Does !empty cause this phenomenon ? Some one please enlighten me as to the error of my ways.

Thanks in advance,

Batoe
Last edited by cap2cap10 on Thu May 19, 2011 9:32 pm, edited 1 time in total.
#programming #issue #mysql #update
  • [DELETED]
    • [1] reply
    • HMMM.. Now on the subject of mysql verses mysqli and mysqli being the improved version.. Thats really just an opinion and to boot lets look at the number of programs developed with mysql VS mysqli.. there is no comparison. MYSQL rules the coding world.

      With that being said, I would def take a look at your post fields on your form and make sure they are correct.

      If you can send a url to the form I will fix it for you whether it be in the code or your form.

      • [1] reply
  • Have you double checked your input form? Are the names where you expect?
  • I cant really see an error inside your code, so my initial guess would also be that you should take a look at your html form!

    offtopic: i would also recommend to stick with mysql in case thats what you are used to (i have never even considered switching to mysqli yet as it is not supposed to actually replace mysql untill php6 [at least thats what i was reading]... probably I am just being dumb and ignorant but whatever )
    • [1] reply
    • Thanks guys, you were right. It was an issue with the form page!

      Batoe

Next Topics on Trending Feed

  • 8

    Here I am again, members of the php technorati, with another strange issue. This time it is my update script. Here is the code: Syntax: [ Download ] [ Hide ] [ Select ] [ Expand ] if (!empty($_POST['submit_1']))