Jump to content


Photo

Weird MySQL/Form problem


  • Please log in to reply
6 replies to this topic

#1 Nolongerused3921

Nolongerused3921
  • Members
  • PipPipPip
  • Advanced Member
  • 142 posts

Posted 13 March 2006 - 05:55 PM

Okay well let me explain the situation: I'm currently writing a moderate users area for a site I'm working on, now thats all fine and dandy - pretty easy to do... However I've run into a major, very annoying bug that only seems to surface on my non-test machine (Non-localhost).

The problem basically is this: When you edit a user, all of the forms are filled out and you are allowed to edit them (Username, location, etc.) and finally you can submit these changes, however - the first time a user is edited, ALL of the data is erased - the form data is SENT, I've checked this by printing the $_POST's, but MySQL just doesn't update the user THE FIRST TIME - its updated the second, third, fourth, etc. time... But never the first.

My code:
    $user_id_e = $var1;
    $username_e = $_POST['username'];
    $email_e = $_POST['email'];
    $country_e = $_POST['country'];
    $fav_genre_e = $_POST['fav_genre'];
    $fav_artist_e = $_POST['fav_artist'];
    $user_level_e = $_POST['user_level'];
    
    $mysql->query("UPDATE users SET username='$username_e', email='$email_e', country='$country_e', fav_genre='$fav_genre_e', fav_artist='$fav_artist_e', user_level='$user_level_e' WHERE id='$user_id_e'", "update_user");

The $mysql->query is just a basic function to run a query and put it into a cache to call up later (To get fetch_row, affected_rows, etc.)

Does anyone know what in gods name could be going wrong? Any ideas at all? I'm willing to accept even the most off the wall "Sun spots" explaination... I just need to know why this isn't working THE FIRST TIME, but does all times after that.

#2 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 13 March 2006 - 07:24 PM

can you post the query method ? i am sure the problem lies in there.. [=

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#3 Nolongerused3921

Nolongerused3921
  • Members
  • PipPipPip
  • Advanced Member
  • 142 posts

Posted 13 March 2006 - 07:27 PM

[!--quoteo(post=354613:date=Mar 13 2006, 01:24 PM:name=keeB)--][div class=\'quotetop\']QUOTE(keeB @ Mar 13 2006, 01:24 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
can you post the query method ? i am sure the problem lies in there.. [=
[/quote]

I thought that was the problem at first too, but, well - take a look for yourself :(
    function query($the_query, $cached_name) {
        $this->query_id = mysql_query($the_query);
    
        if (! $this->query_id )
        {
            $this->fatal_error("mySQL query error: $the_query");
        }
    
        $this->query_count++;
        $this->obj["cached_queries"]["$cached_name"] = $this->query_id;
        return $this->query_id;
    }


#4 keeB

keeB
  • Staff Alumni
  • Advanced Member
  • 1,078 posts
  • LocationCalifornia

Posted 13 March 2006 - 07:33 PM

What a weird method :D

Try commenting out everything in the middle layer.. see if that helps.. and.. what does that do? can you post the method for that one?


  public  function query($the_query, $cached_name) {
        $this->query_id = mysql_query($the_query);
      
/*
        if (! $this->query_id )
        {
            $this->fatal_error("mySQL query error: $the_query");
        }
    
        $this->query_count++;
*/ 
        $this->obj["cached_queries"]["$cached_name"] = $this->query_id; //what does this do??
        return $this->query_id;
    }

Come visit my site to see my latest projects
http://nick.stinemates.org/wordpress/


#5 Nolongerused3921

Nolongerused3921
  • Members
  • PipPipPip
  • Advanced Member
  • 142 posts

Posted 13 March 2006 - 07:38 PM

[!--quoteo(post=354617:date=Mar 13 2006, 01:33 PM:name=keeB)--][div class=\'quotetop\']QUOTE(keeB @ Mar 13 2006, 01:33 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
What a weird method :D

Try commenting out everything in the middle layer.. see if that helps.. and.. what does that do? can you post the method for that one?
  public  function query($the_query, $cached_name) {
        $this->query_id = mysql_query($the_query);
      
/*
        if (! $this->query_id )
        {
            $this->fatal_error("mySQL query error: $the_query");
        }
    
        $this->query_count++;
*/ 
        $this->obj["cached_queries"]["$cached_name"] = $this->query_id; //what does this do??
        return $this->query_id;
    }
[/quote]

Basically it allows you to put a query into an array filled with other cached queries, so you can use other functions on them such as fetch_rows, affected_rows, etc. - without having to rewrite the query.
And the bug is still there even after commenting :(
Its weird, the UPDATE statement only makes THAT row blank on the FIRST time for THAT row... As in, if I update user2 the first time, no matter what I change or even if I leave everything the same - it clears everything the update query SETs... However, Every time after that - it works correctly.

#6 Nolongerused3921

Nolongerused3921
  • Members
  • PipPipPip
  • Advanced Member
  • 142 posts

Posted 14 March 2006 - 02:26 AM

Hate to bump, but bump :(

#7 Nolongerused3921

Nolongerused3921
  • Members
  • PipPipPip
  • Advanced Member
  • 142 posts

Posted 14 March 2006 - 03:47 PM

Anyone?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users