7 replies
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.
#issue #mysql #update
  • Profile picture of the author Terry Crim
    [DELETED]
    {{ DiscussionBoard.errors[3919209].message }}
    • Profile picture of the author newbie365
      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.

      {{ DiscussionBoard.errors[3920240].message }}
      • Profile picture of the author SteveJohnson
        Originally Posted by newbie365 View Post

        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.
        It appears that you're missing the boat somewhere. The terms 'mysql' and 'mysqli' refer to the PHP MySQL extensions. 'mysqli' is indeed the improved version of the 'mysql' extension, and that isn't opinion.
        Signature

        The 2nd Amendment, 1789 - The Original Homeland Security.

        Gun control means never having to say, "I missed you."

        {{ DiscussionBoard.errors[3921617].message }}
        • Profile picture of the author newbie365
          Not sure I want to be on your boat! But you said it yourself and I will quote you here "mysqli is the improved version"... That is INDEED your opinion.. the fact of the matter is, why should he change his coding practices to YOUR improved version? He asked a question that was simple to answer and you want to turn it into an argument on whether or not mysql vs mysqli is better than the other.. well ok, Im game for this. Are we going to have a programming battle now? PLEASE SAY YES!!
          {{ DiscussionBoard.errors[3921900].message }}
          • Profile picture of the author newbie365
            Also, shall we bring MYSQL server and PHP versions into this discussion? Without even knowing what kind of server hes on or his config etc.. Your suggesting that he changes to mysqli NICE.. NOT.
            {{ DiscussionBoard.errors[3921943].message }}
  • Profile picture of the author KirkMcD
    Have you double checked your input form? Are the names where you expect?
    {{ DiscussionBoard.errors[3919995].message }}
  • Profile picture of the author andrejvasso
    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 )
    {{ DiscussionBoard.errors[3922455].message }}
    • Profile picture of the author cap2cap10
      Thanks guys, you were right. It was an issue with the form page!

      Batoe
      {{ DiscussionBoard.errors[3925081].message }}

Trending Topics