SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2001
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Confusing problem

    I have created a page where the user has to guess who the person in a picture is.

    In the first page I made an answer array that boasts the name of the person in the picture itself:

    $answer = array("Lee Bowyer");

    I'd like to note that I created an array because I'm planning to have the page randomly pick pictures from an array boasting tons of them.
    I also sent all the arrays/variables needed in the second page from the first via a number of hidden form fields.

    Back to the problem. If I type Lee Bowyer in the text field the next page tells me I've guessed wrong when it's clear I've got it spot on.

    I echoed out the $player_in_picture variable(which is basically the randomnly picked picture's answer, hope you're still with me) in the second page and to my surprise it read: Lee and not Lee Bowyer. Thus even if you typed in the correct answer you'll be told you guessed wrong because $player_in_picture equals to Lee and not Lee Bowyer. Here's the code to make things clearer...

    PHP Code:
    $who_am_i = array("http://www.sigames.com/dev/images/whoami_bowyer2.gif","http://www.sigames.com/dev/images/whoami_bowyer2.gif");
    $answer = array("Lee Bowyer","Lee Bowyer");
    $who_am_i_number rand(1,2) - 1
    $picture $who_am_i[$who_am_i_number];
    $player_in_picture $answer[$who_am_i_number]; 
    I have no idea why but I'm really keen on finding out.
    Bardius

  2. #2
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    So how is it you are passing the asnwer to the second page? Hidden form inputs? Sounds like the hidden form input that passes the answer is missing quotes around the value attribute, that usually causes values with more than one word to only send the first word, since html doesn't know how to handle the space.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  3. #3
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Very peculiar indeed.. especially when I copied the code, ran it, and "Lee Bowyer" came up. It works perfectly for me. Is it still only showing up "Lee" for you when you echo $player_in_picture?

    By the way, you should srand(mktime()); right before you make the call to $who_am_i_number = rand(1,2) - 1; for better results.

  4. #4
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    cupid, I do believe they are passing those values to the next page via hidden form inputs.
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  5. #5
    epsilon transition cupid's Avatar
    Join Date
    Aug 2001
    Location
    Kent, Ohio
    Posts
    367
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ohhhhh you're a step ahead of me buddy! I didn't understand what he was trying to do exactly, obviously. Thanks for pointing that out.

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2001
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sounds like the hidden form input that passes the answer is missing quotes around the value attribute
    Indeed and adding the quotes worked like a charm. Thanks alot guys.

    However, there's one tiny little thing that I thought I need to consider and that's if the user types in "lee bowyer" and not a grammaticaly correctly capitalized "Lee Bowyer"

    I tried that and was told that I took the wrong guess. I doubt there's anyway round this, right?
    Bardius

  7. #7
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you don't care about case, then just convert both to all lower case before comparing the two. using strtolower().

    PHP Code:
    if(strtolower($var1) == strtolower($var2)) {
    //do something

    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  8. #8
    SitePoint Zealot
    Join Date
    Mar 2001
    Posts
    143
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Right that came in handy.

    One final query I have concerning all this and that's how I could overcome the following situation. If the user puts down only "Bowyer" as the answer, which is actually correct. However, he will be told it's incorrect, since the variable is set as Lee Bowyer and not Bowyer.

    I guess the ereg function comes in handy over here. But I wouldn't know how to use it in the situation I'll be in seeing as there'll be a different randomnly picked picture to guess who it is everytime the user comes to the page.
    Bardius


Bookmarks

Posting Permissions

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