Jump to content

[SOLVED] Can someone review this code please?


rh-penguin

Recommended Posts

Im trying to make a script where a user needs to input a specific number in order to move on to a diferent page(kinda like a login). This is what i've got so far but line 22(where the form starts) seems to have got me.........I dont know maybe the other code is crap???? ???

<html><head><title>Random number</title></head>
<body>
<?php
$random_number = rand(1567, 9884);
echo "Random number is:" . $random_number ;
?>

<?php 
$enter_code = $_POST['enter_code'];
$self = $_SERVER['PHP_SELF'];
?>

<?php 
if(isset($_POST['enter_code']) and ($_POST['enter_code'] = $random_number) ) {
echo "<a href=go_on.php>Continue!</a>; 
} else {
echo ('Try again!');
} 
?>


<form action="<?php $self ?>" method="post">
Code: <input type="text" name="enter_code"><br>
</form>

</body>
</html>

Link to comment
Share on other sites

The comparison operator is == and not =.

The if line should be like this:

if(isset($_POST['enter_code']) and ($_POST['enter_code'] == $random_number) ) {

 

Also, you didn't close the double quotes in the echo statement. It should be like this:

echo "<a href=go_on.php>Continue!</a>";

 

 

Orio.

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.