illadelphiakid Posted October 14, 2011 Share Posted October 14, 2011 Please help, i'm writing a code that a user must match a random word ($word) from a choice of definitions ($word_defs)...No matter what definition is picked from the list, the response is always 'incorrect', can someone please look at my code and tell me what's wrong? Here is the entry code: require_once "include/word_defs.php"; $word = array_keys($word_defs); $word_defs = array_unique(array_values($word_defs)); $session = new Session(); $params = (object) $_REQUEST; if (isset($params->guess)) { $word = $params->word; if ( $params->word_defs == $word_defs[$word] ) { $response = "correct"; } else { $response = "incorrect"; } $choices->word_def[$params->word_defs] = "selected"; } else { $word = $word[ rand( 0, count($word)-1 ) ]; } Code in body: word: <?php echo $word ?> <form action="?" method="get"> definition: <select name="word_defs"> <?php foreach ($word_defs as $word_def): ?> <option <?php echo $choices->word_def[$word_def] ?> ><?php echo $word_def?></option> <?php endforeach ?> </select> <input type="submit" name="guess" value="Guess" /> <input type="hidden" name="word" value="<?php echo $word?>" /> </form> <h3><?php echo $response ?></h3> Quote Link to comment https://forums.phpfreaks.com/topic/249095-problems-with-sessionsarrays/ Share on other sites More sharing options...
joel24 Posted October 14, 2011 Share Posted October 14, 2011 try running print_r($_GET) and print_r($_SESSION) and see what variables are set are you starting the session properly/including the session() class you call? Quote Link to comment https://forums.phpfreaks.com/topic/249095-problems-with-sessionsarrays/#findComment-1279259 Share on other sites More sharing options...
illadelphiakid Posted October 14, 2011 Author Share Posted October 14, 2011 try running print_r($_GET) and print_r($_SESSION) and see what variables are set are you starting the session properly/including the session() class you call? I get an error trying to print session but printing get, i receive this: Array ( [word_defs] => To recant, renounce, repudiate under oath. [guess] => Guess [word] => abjure ) The word and def are correct, but response says incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/249095-problems-with-sessionsarrays/#findComment-1279261 Share on other sites More sharing options...
joel24 Posted October 14, 2011 Share Posted October 14, 2011 what's the error? Quote Link to comment https://forums.phpfreaks.com/topic/249095-problems-with-sessionsarrays/#findComment-1279265 Share on other sites More sharing options...
illadelphiakid Posted October 14, 2011 Author Share Posted October 14, 2011 what's the error? Uhh nvm i spelled something wrong. i get this Array ( [word_defs] => To recant, renounce, repudiate under oath. [guess] => Guess [word] => abjure ) Array ( ) Quote Link to comment https://forums.phpfreaks.com/topic/249095-problems-with-sessionsarrays/#findComment-1279266 Share on other sites More sharing options...
Buddski Posted October 14, 2011 Share Posted October 14, 2011 You arent assigning a value to your option tags. Quote Link to comment https://forums.phpfreaks.com/topic/249095-problems-with-sessionsarrays/#findComment-1279352 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.