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. 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']; 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. Link to comment https://forums.phpfreaks.com/topic/167360-post-does-not-work/#findComment-882587 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.