fabiez Posted December 14, 2014 Share Posted December 14, 2014 what am i doing wrong? I can't see it... I want to catch the rand variable but it doesn't. So I print an extra print at the bottom. So there should be two rand prints. Here's the code. <html> <head><title></title> </head> <body> <form action='random.php' method='post'> <?php if(isset($_REQUEST['rand'])){ $rand = $_REQUEST['rand']; print $rand . "<br /><br />"; } else { print "rand: empty<br /><br />"; } $rand = rand(1,1000); print $rand."<br /><br />"; print "<input type='hidden' value='$rand' />"; ?> <input type='submit' value='scramble' /> </form> </body> </html> I forgot to tell ya that the if statement returns rand: empty. Help... Link to comment https://forums.phpfreaks.com/topic/293092-rand-not-working/ Share on other sites More sharing options...
mac_gyver Posted December 14, 2014 Share Posted December 14, 2014 <input type='hidden' value='$rand' /> ^^^ your form field doesn't have a name='rand' attribute, so, there is no $_POST['rand'] or in your case $_REQUEST['rand'] value. only form fields with name's are submitted, as that's the only way for the value to be identified. Link to comment https://forums.phpfreaks.com/topic/293092-rand-not-working/#findComment-1499570 Share on other sites More sharing options...
fabiez Posted December 14, 2014 Author Share Posted December 14, 2014 thank you Link to comment https://forums.phpfreaks.com/topic/293092-rand-not-working/#findComment-1499574 Share on other sites More sharing options...
hansford Posted December 14, 2014 Share Posted December 14, 2014 I would like to see some attempts at error reporting and some printed feedback as to just what exactly is getting returned from things such as forms, functions/methods. After your opening <?php tag you should have full error reporting turned on when in debug mode. <?php error_reporting(E_ALL); ini_set('display_errors', 1); Before you attempt to execute an query - echo it out to the screen or log the query to a file for viewing. $query = "SELECT Student_Id, Lname, Fname FROM Students WHERE Student_Id = '$id'"; echo $query; exit; When your form is submitted to the php page for processing - print the values of what the $_POST array contains. if (isset($_POST['some_value'])) { echo '<pre>'; print_r($_POST); echo '</pre>'; } Link to comment https://forums.phpfreaks.com/topic/293092-rand-not-working/#findComment-1499579 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.