jdock1 Posted April 7, 2010 Share Posted April 7, 2010 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? Link to comment https://forums.phpfreaks.com/topic/197836-whats-wrong-with-this-code-not-working-as-expected/ Share on other sites More sharing options...
teamatomic Posted April 7, 2010 Share Posted April 7, 2010 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 Link to comment https://forums.phpfreaks.com/topic/197836-whats-wrong-with-this-code-not-working-as-expected/#findComment-1038186 Share on other sites More sharing options...
jdock1 Posted April 7, 2010 Author Share Posted April 7, 2010 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? Link to comment https://forums.phpfreaks.com/topic/197836-whats-wrong-with-this-code-not-working-as-expected/#findComment-1038188 Share on other sites More sharing options...
teamatomic Posted April 7, 2010 Share Posted April 7, 2010 </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 Link to comment https://forums.phpfreaks.com/topic/197836-whats-wrong-with-this-code-not-working-as-expected/#findComment-1038190 Share on other sites More sharing options...
trq Posted April 7, 2010 Share Posted April 7, 2010 <?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; } ?> Link to comment https://forums.phpfreaks.com/topic/197836-whats-wrong-with-this-code-not-working-as-expected/#findComment-1038191 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.