Jump to content

Weird MySQL/Form problem


Nolongerused3921

Recommended Posts

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:
[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");
[/code]

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.
Link to comment
Share on other sites

[!--quoteo(post=354613:date=Mar 13 2006, 01:24 PM:name=keeB)--][div class=\'quotetop\']QUOTE(keeB @ Mar 13 2006, 01:24 PM) [snapback]354613[/snapback][/div][div class=\'quotemain\'][!--quotec--]
can you post the [b]query[/b] 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 :(
[code]
    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;
    }
[/code]
Link to comment
Share on other sites

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?


[code]  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;
    }[/code]
Link to comment
Share on other sites

[!--quoteo(post=354617:date=Mar 13 2006, 01:33 PM:name=keeB)--][div class=\'quotetop\']QUOTE(keeB @ Mar 13 2006, 01:33 PM) [snapback]354617[/snapback][/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?
[code]  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;
    }[/code]
[/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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.