Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts

    reload page if query successful

    Quite hard to explain, so shall try and if I make no sense, please ask.

    Page is displayed taking info from a database depending on a particular field (user_riddle) of the user. Page also has a form at the end.

    User enters details to the form and submits - which reloads the page.

    If the data is false. the page reloads as before - no problem here.
    If the data is true, user_riddle increments by 1, which should result in a different set of info coming out of the database.

    However, the script runs as before, and I need to manually refresh the page for the database to be queried again to get the new info. I would like to reload the page after the user_riddle has incremented...how can I do this?

    PHP Code:
    <?php
    // Request the user_riddle number 
    global $userdata;
     echo 
    '<p>Riddle answer # ' .$userdata[user_riddle].'</p>';
        
    // Request the text of selected riddle 
       
    global $userdata;
       
    $currentanswer = @mysql_query("SELECT answer FROM phpbb_riddles WHERE riddleid = $userdata[user_riddle]"); 

    if (!
    $currentanswer) { 
        die(
    "<p>Error performing query: " mysql_error() . "</p>"); 

    // Display the text of selected riddle in a paragraph 

    while ( $row mysql_fetch_array($currentanswer) ) { 
        
    $user_answer $row['answer'];
         echo 
    '<p>Riddle answer '.$user_answer.'</p>';
     } 
        
     
    // Check answer and update user riddle by one increment if correct
     
    $youranswer $_POST['youranswer'];
    if ( 
    $youranswer == $user_answer 
    {
    global 
    $userdata
    echo( 
    'Well done ' .$userdata[username].', that was the right answer' );
    $incrementin $userdata[user_riddle] + 1;
    global 
    $userdata
      
    $sql 'UPDATE `phpbb_users` SET `user_riddle` = user_riddle + 1 WHERE `username` = \'anonymous\' ';
      if ( @
    mysql_query($sql) ) { 
     echo(
    '<p>Update affected ' mysql_affected_rows() . 
          
    ' rows.</p>'); 
          else { 
     die(
    '<p>Error performing this effing update: ' mysql_error() . 
         
    '</p>'); 
    }
    echo 
    '<p>number is '.$incrementin.', okay?</p>'
    } else {
    echo( 
    'bad luck' );


    // Request the text of selected riddle 
       
    global $userdata;
       
    $currentriddle = @mysql_query("SELECT riddle FROM phpbb_riddles WHERE riddleid = $userdata[user_riddle] "); 

    if (!
    $currentriddle) { 
        die(
    "<p>Error performing query: " mysql_error() . "</p>"); 

    // Display the text of selected riddle in a paragraph 

    while ( $row mysql_fetch_array($currentriddle) ) { 
        
    $user_riddle $row['riddle'];
         echo 
    '<p>Riddle '.$user_riddle.'</p>';
    }
      
    ?>
    The // Request the text of selected riddle part of the page is the part that is not querying the db on the UPDATE information that has just been entered - so I assume a reload must be used here.

    Cheers

    Mxx
    "Imagination is more important than knowledge" A. Einstein's 'Twin Paradox'

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    I'll have a look tomorrow for you if no one else answers before. Too tired to do anymore coding today or even look at any code lol

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A lifesaver once again...thanks.

    Luckily there's only a few more things that need doing to the script before it's complete.

    Mxx
    "Imagination is more important than knowledge" A. Einstein's 'Twin Paradox'

  • #4
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Shouldn't

    WHERE riddleid = $userdata[user_riddle]

    be

    WHERE riddleid = $incrementin

    ?
    Where on top of the page, you set
    $incrementin =$userdata[user_riddle] ;
    and then , if the answer was correct, you increment it like
    $incrementin ++;

    This way, the next ridle will be selected if the answer was true, but the same will be selected it the answer was false.
    Last edited by raf; 01-08-2004 at 12:26 AM.

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    EDITED AT BOTTOM

    Sorry raf, I'm not 100% sure what you mean by that...would it be possible for you to change the appropriate parts of the code to reflect what you suggested? I attempted to change them but the script wouldn't load properly.

    Many thanks

    EDIT: Scrub that. I redid it again and it works Cheers raf...that saves having to reload the page. woot!

    Mxx
    Last edited by murphyz; 01-08-2004 at 10:11 PM.
    "Imagination is more important than knowledge" A. Einstein's 'Twin Paradox'

  • #6
    raf
    raf is offline
    Master Coder
    Join Date
    Jul 2002
    Posts
    6,589
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Glad you got it running


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •