Jump to content

rand not working


fabiez
Go to solution Solved by mac_gyver,

Recommended Posts

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
Share on other sites

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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.