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.
Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts

    direct user based on lookup info

    The scenario is I'm building a riddle site, and I want riddles to be hidden from a user until they have passed the previous one.

    therefore, riddle.php is only viewable when the user is logged into the site - that bit is easy.

    Answering the riddle on this page leads the user onto, for example, welldone.php. As well as the usual check to ensure the user is logged in on this page, I want to do another check to make sure they have the correct answer specified on riddle.php - meaning they can continue from where they left off.

    I think I would need the answers to be stored under the username as tney pass the riddles and then, when returning to riddle.php (or any of the other riddle pages) there is a lookup performed on the database to see where they were last time.

    Any ideas as to the best way to go about this, or specific areas I need to look up on?

    Many thanks

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

  • #2
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    In your database you should have at a minium something like this for tables

    TableName: riddles
    Columns:
    riddle_id, riddle, answer

    TableName: users
    Columns:
    userid, password, last_riddle

    When they login you check to see what the last riddle_id was stored in the last_riddle column for their record. Based on that you display the corresponding riddle they should start with for that session.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #3
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    yip, that makes sense, thanks.

    for the riddle table, the info would be something such as:

    riddleid = 1
    riddle = riddle number one
    answer = your answer

    and as you say, the user_riddle field under the users table would need to update with the riddleid as they put the answer in correctly.

    I have no idea what code I would use on the riddle page to check the answer with the one in the database and, if that is correct, increment the user_riddle field by one.

    At the moment I am using php to check they are logged in, but using cgi to check they have the correct answer.

    mucho confusion - need more coffee

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

  • #4
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    I would hope as far as the answer goes you are giving them a list of answers to choose from? Otherwise it would be pretty much impossible to check for a correct answer using an answer the user types in.

    And yes as they answer a questions correctly you should update the field in the users table to whatever question they last answered correctly. As for incrementing the number that would not be a good idea unless you are absolutely controlling the order all riddles are entered into the system. The riddle_id field can just be an autonumber field that increments when a riddle is added to the system. You should grab that value along with the correct answer when displaying the riddle to the user. If they answer correctly then store the riddle_id that was pulled into the field in the users table.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #5
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    In which case I have hit a snag

    The user does not get a choice of answers, the answer gets typed in and has to match my answer word for word, space for space. I am currently using cgi to check the answer they type and, if incorrect, refresh the page, if correct, move onto the next page.

    What I want to be able to do is make sure that the answers are secure so that a user cannot skip riddles without having the answers to the previous ones.

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

  • #6
    Supreme Overlord Spookster's Avatar
    Join Date
    May 2002
    Location
    Marion, IA USA
    Posts
    6,280
    Thanks
    4
    Thanked 83 Times in 82 Posts
    You can do all of this in PHP. If you do not want them to choose from a list of answers you will have to parse their answer and and build up some kind of smart answer checking system because if they don't spell something correctly or put a more than one space between two words on accident doesn't mean they had the answer wrong but just can't type well. You would need a system that knows to check for every possible wrong way of typing something a user might do. Obviously it would be easier to give them a list of possible answers and let them choose which one they think is correct.
    Spookster
    CodingForums Supreme Overlord
    All Hail Spookster

  • #7
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Unfortunately the optional answer isn't an option for me, and any answers they do give would be very reliant on spelling (or in some cases miss-spelling) so I don't mind not giving them any leniancy on mistakes. All of the users are used to these type of riddles where their answers are very specific so I don't need to worry about that.

    Unfortunately I don't know enough php to figure it all out.

    Cheers

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

  • #8
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I'm approaching this from a slightly different angle to previous, using similar tables as suggested by Spookster above.

    I currently have one page which needs to display a specific riddle depending on the user viewing the page and how far they have got.

    Therefore, I want it so that if the user_riddle field within phpbb_users for someone says '2', then riddle '2' should be displayed. However, I keep getting an error on line 5 of this code:

    PHP Code:
      <?php 
    // Request current riddle ID for user
    $current = @mysql_query('SELECT `user_riddle` '
            
    'FROM `phpbb_users` '
            
    'WHERE 1 AND `username` = \'murphyz\' LIMIT 0, 30'); 
    if (!
    $current) {
      die(
    '<P>Error performing query: 'mysql error() . 
            
    '</p>');
          }
        
    // Display the current riddle in a paragraph 
     
    while ( $row mysql_fetch_array($current) ) { 
       echo(
    '<p>' $row['user_riddle'] . '</p>'); 
     } 
       
     
    // Request the text of a specific riddle 
     
    $result = @mysql_query('SELECT `riddle` '
            
    'FROM `phpbb_riddle` '
            
    'WHERE 1 AND `riddleid` = 2 LIMIT 0, 30'); 
     if (!
    $result) { 
       die(
    '<p>Error performing query: ' mysql_error() . 
           
    '</p>'); 
     } 

     
    // Display the text of selected riddle in a paragraph 
     
    while ( $row mysql_fetch_array($result) ) { 
       echo(
    '<p>' $row['riddle'] . '</p>'); 
     } 

    ?>
    At the moment the above should just store the user_riddle number into the $current variable and then display it on the page. Once I get this to work I would like to change the line:
    PHP Code:
    'WHERE 1 AND `riddleid` = 2 LIMIT 0, 30'); 
    to act something such as
    PHP Code:
    'WHERE 1 AND `riddleid` = $current LIMIT 0, 30'); 
    Any help on why the first part of the code isn't working would be greatly appreciated.

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

  • #9
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Need to add backslashes

    . 'WHERE 1 AND `username` = \'murphyz\' LIMIT 0, 30');

  • #10
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I had those in the script, but the 'php' BBCODE button seems to have altered it on it's own to read 'murphyz'.

    If, as moderator, you can edit the first post you can see they are in there.

    EDIT: Darn, thought you were a mod

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

  • #11
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Jsut noticed, what is this 1 AND in the query doing?

    It's probably that that's throwing the error as they're not doing anything

    <edit>I'd be dangerous if I was a mod lol</edit>

  • #12
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have no idea what they are doing, I was using the php output produced my phpmyadmin. I attempted removing it, but still nothing.

    The second part of the code, dealing with the $result, works fine on it's own.

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

  • #13
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    hmm,

    The above seems to work fine if used on just one line like such:

    PHP Code:
    $result = @mysql_query('SELECT user_riddle FROM phpbb_users WHERE username=\'murphyz\''); 
    Now, I'm curious as to whether or not I am able to use the $result within another mysql_query?

    Can't get the following to work...

    PHP Code:
    $currentriddle = @mysql_query('SELECT riddle FROM phpbb_riddles WHERE riddleid=$result'); 
    Cheers

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

  • #14
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    Variables don't work when they're in single quotes. For it to work that way, use double quotes.

    $currentriddle = @mysql_query("SELECT riddle FROM phpbb_riddles WHERE riddleid=$result");

  • #15
    Regular Coder
    Join Date
    Jun 2002
    Location
    London
    Posts
    220
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That comes back with the following error:

    PHP Code:
    Error performing queryYou have an error in your SQL syntax near 'id #24' at line 1 
    Earlier I was testing writing information to a table, such as attempted answers from a particular user. The riddleid when I went to do this kept coming back as Resource #24 - instead of '1'. Now it seems that #24 is appearing in the above error.

    any idea why that might be?

    Mxx

    (thanks for your patience and help)
    "Imagination is more important than knowledge" A. Einstein's 'Twin Paradox'


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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