Jump to content

Whats wrong with this code? Not working as expected


jdock1

Recommended Posts

I used to mess with PHP all the time but quit for almost a year, so im a little rusty.

 

I wrote this code up;

 

<?php
$form = "<center>
<form action='access.php' method='get'>
<input type='text' name='code'/>
<input type='submit' value='Access'/></center>";

$code = $_GET['code'];

if ($code == "071691");
{
unset ($code);
}

$code = Access code accepted.";


?>

 

Im expecting, when I enter 071691, that it unsets the $form which would be the html form and replaces it with the text "access code accepted".

 

What am I doing wrong here?

You need to terminate the form. You also need to replace the unset with the $code='blah blah' and just leave the form to display. If you dont want the form to show after the submit do it with logic...

if(isset($_GET['submit']))

{do the code thing}

else

{display the form}

 

 

HTH

Teamatomic

You need to terminate the form. You also need to replace the unset with the $code='blah blah' and just leave the form to display. If you dont want the form to show after the submit do it with logic...

if(isset($_GET['submit']))

{do the code thing}

else

{display the form}

 

 

HTH

Teamatomic

 

Thanks but I still dont get it. I never messed with isset and I swear that I used unset like that before. How would I terminate the form?

</form>

 

1. You never echo out $form so it will never display.

2. You have a conditional to unset $code

3. below the unset conditional you set $code to 'Access code accepted'

4. No matter what is the value of $code it will always be 'Access code accepted'

5. I gave you the solution, fill it in with your form and $code change

 

 

 

HTH

Teamatomic

<?php
$form = "<center>
<form action='access.php' method='get'>
<input type='text' name='code'/>
<input type='submit' value='Access'/></center>";

if (isset($_GET['code'])) {
  $code = $_GET['code'];
  if ($code == "071691") {
    unset ($code);
    echo "Access code accepted.";
  }
} else {
  echo $form;
}
?>

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.