phpllama Posted July 25, 2009 Share Posted July 25, 2009 cash.php <?php $file = file('./file.txt'); $line = $file[array_rand ($file)]; $split = explode(",", $line); $name = $split[0]; $number = $split[1]; if($_POST['numbers'] == $number){ echo 'True'; } else { echo 'False'; } ?> <form action="cash.php" method="post"> <?php echo "$name: "; ?><input name="numbers" type="text" /><input type="submit" /> </form> file.txt banana,1 orange,2 grape,3 lemon,4 The PHP reads the text file, chooses a random line, splits it up by comma into $name and $number. The form basically checks $number is correct. But it does not work correctly and comes up false. Quote Link to comment https://forums.phpfreaks.com/topic/167360-post-does-not-work/ Share on other sites More sharing options...
smerny Posted July 25, 2009 Share Posted July 25, 2009 find out exactly what isnt working before the IF statement, echo "number = ".$number."<br /> post numbers = ". $_POST['numbers']; Quote Link to comment https://forums.phpfreaks.com/topic/167360-post-does-not-work/#findComment-882507 Share on other sites More sharing options...
wildteen88 Posted July 25, 2009 Share Posted July 25, 2009 This line $file = file('./file.txt'); Needs to be $file = array_map('trim', file('./file.txt')); Now your code will work as you expected. Quote Link to comment https://forums.phpfreaks.com/topic/167360-post-does-not-work/#findComment-882587 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.