yakoup46 Posted April 21, 2009 Share Posted April 21, 2009 Code: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN"> <html> <head> <title></title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> First name: <input type="text" name="first_name"><br> Last name: <input type="text" name="last_name" style="position: relative; left: 1px;"> <input type="submit" value="Submit"> </form> <?php $first = @$_POST['first_name']; $last = @$_POST['last_name']; $charecter = array("is gay", "is cool", "is a funny", "is a wierdo", "is just dumb"); $doing = array("farts alot", "runs in circles", "...", "and loves strawberry shortcake"); $number = range('0','9'); $test = ($number[rand(0,9)]) . ($number[rand(0,9)]); if(!empty($first) && ($last)) echo $first . " " . $last . " " . $charecter[rand(0,4)] . " and " . $doing[rand(0,3)] . "<br /> Lucky Number: " . $test . "."; if($test < 99 && $test > 50) echo "That is a great number!"; ?> </body> </html> So my problem is that when i load the page a number is immediately generated before i press submit and the echo "that is a great number" may show up before i press submit because it is as if the random number was generated before i pressed submit. So what i am asking is can i make the script wait until i press submit before it decides whether or not it is a lucky number? Quote Link to comment Share on other sites More sharing options...
Prismatic Posted April 21, 2009 Share Posted April 21, 2009 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN"> <html> <head> <title></title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> First name: <input type="text" name="first_name"><br> Last name: <input type="text" name="last_name" style="position: relative; left: 1px;"> <input type="submit" value="Submit"> </form> <?php $first = $_POST['first_name']; $last = $_POST['last_name']; $charecter = array("is gay", "is cool", "is a funny", "is a wierdo", "is just dumb"); $doing = array("farts alot", "runs in circles", "...", "and loves strawberry shortcake"); $number = range('0','9'); $test = ($number[rand(0,9)]) . ($number[rand(0,9)]); if($_POST['submit']) { if(!empty($first) && ($last)) { echo $first . " " . $last . " " . $charecter[rand(0,4)] . " and " . $doing[rand(0,3)] . "<br /> Lucky Number: " . $test . "."; } if($test < 99 && $test > 50) { echo "That is a great number!"; } } ?> Quote Link to comment Share on other sites More sharing options...
yakoup46 Posted April 21, 2009 Author Share Posted April 21, 2009 After i did that it wouldn't display anything. ??? Quote Link to comment Share on other sites More sharing options...
AE117 Posted April 21, 2009 Share Posted April 21, 2009 Put your random generator in to a function call it what ever you like and the you need to change your sumbit button to call that function Soo <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> Turns into <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" onsubmit="return yourfunction();"> function yourfunction () { if(!empty($first) && ($last)) { echo $first . " " . $last . " " . $charecter[rand(0,4)] . " and " . $doing[rand(0,3)] . "<br /> Lucky Number: " . $test . "."; } if($test < 99 && $test > 50) { echo "That is a great number!"; } } Quote Link to comment Share on other sites More sharing options...
yakoup46 Posted April 21, 2009 Author Share Posted April 21, 2009 Still nothing it returns blank. I did exactly everything you said. I even copied exactly what you had into a new document and still nothing. ??? Quote Link to comment Share on other sites More sharing options...
AE117 Posted April 21, 2009 Share Posted April 21, 2009 Still nothing it returns blank. I did exactly everything you said. I even copied exactly what you had into a new document and still nothing. ??? Question for you the other guy before me change your $first = @$_POST['first_name']; $last = @$_POST['last_name']; to $first = $_POST['first_name']; $last = $_POST['last_name']; did you keep that change and you might want to try a $_REQUEST instead of post or and just saw this function yourfunction () { if(!empty($first) && ($last)) Should be function yourfunction () { if(empty($first) && ($last)) Quote Link to comment Share on other sites More sharing options...
yakoup46 Posted April 21, 2009 Author Share Posted April 21, 2009 still nothing. and when i remove the @ i get the stupid 'Undefined index' error. Quote Link to comment Share on other sites More sharing options...
AE117 Posted April 21, 2009 Share Posted April 21, 2009 still nothing. and when i remove the @ i get the stupid 'Undefined index' error. I almost got it and then my damn server failed but this will get you way start Pretty much it only checks to see if the first name is filled in not first and last <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 TRANSITIONAL//EN"> <html> <head> <title></title> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> First name: <input type="text" name="first_name"><br> Last name: <input type="text" name="last_name" style="position: relative; left: 1px;"> <input type="submit" value="Submit"> </form> <?php $first = @$_POST['first_name']; $last = @$_POST['last_name']; $charecter = array("is gay", "is cool", "is a funny", "is a wierdo", "is just dumb"); $doing = array("farts alot", "runs in circles", "...", "and loves strawberry shortcake"); $number = range('0','9'); $test = ($number[rand(0,9)]) . ($number[rand(0,9)]); if(empty($first)) echo "Please Enter Your First and Last Name"; elseif($first=$first) echo $first . " " . $last . " " . $charecter[rand(0,4)] . " and " . $doing[rand(0,3)] . "<br /> Lucky Number: " . $test . "."; elseif($test < 99 && $test > 50) echo "That is a great number!"; ?> </body> </html> Quote Link to comment 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.