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>

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.