ProLogiC Posted April 26, 2008 Share Posted April 26, 2008 Hi there, I'm very new to php and have been following a guide from www.learnphpfree.com I was reading through Lesson 7 although I still do not understand the $_GET and $_POST I continued with this script but adjusted it to suit me. here is my code <form action="if.php" method="get"> <!--//Make the HTML Form --> Your Number:<input name="num" type="text"> <!--//Make the input box --> <input type="submit" value="Submit"> <!--//Make the Submit botton --> </form> <!--// End the Form --> <?php /* Make a new variable called "$cpu_number" and set it to a random number. */ $cpu_number = rand(0, 100); /* "if" somthing was posted (isset) do the following: */ if (isset($_GET['num'])) { $number = $_GET['num']; /*put the posted variable "num" into a new variable called "$number". */ If ($number > $cpu_number) { /* "if" $number is greater than $cpu_number do the following: */ echo "Your Number Is Bigger! CPU's number is $cpu_number"; } elseif ($number > 100) { echo "Please enter a number between 0 and 100"; } If ($number < $cpu_number) { /* "if" $number is less than $cpu_number do the following: */ echo "Your Number Is Smaller! CPU's number is $cpu_number"; } if ($number == $cpu_number) { echo "You picked the same number as me!"; } /*if ($number > 100) { echo "But please enter a number between 0 and 100"; }*/ } I told the script to ignore my last if statement as it did work but with only one problem If the number was over 100 it was still saying "Your number is bigger" but I wanted it to only say that if my number was bigger but not over 100 Could someone please help me and if anyone has a better source to learn PHP I would be greatful, but I must warn you, I have zero knowledge of html or any other coding language so I really am starting from the very beginning on PHP. Quote Link to comment https://forums.phpfreaks.com/topic/102987-basic-php/ Share on other sites More sharing options...
sasa Posted April 26, 2008 Share Posted April 26, 2008 change order of if statemans 1st check is biger the 100 If ($number > 100) { /* "if" $number is greater than $cpu_number do the following: */ echo "Please enter a number between 0 and 100"; } elseif ($number > $cpu_number) { echo "Your Number Is Bigger! CPU's number is $cpu_number"; } Quote Link to comment https://forums.phpfreaks.com/topic/102987-basic-php/#findComment-527579 Share on other sites More sharing options...
ProLogiC Posted April 26, 2008 Author Share Posted April 26, 2008 Thank you Quote Link to comment https://forums.phpfreaks.com/topic/102987-basic-php/#findComment-527708 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.