jlgray48 Posted March 7, 2007 Share Posted March 7, 2007 I am trying to create a basic program for a college class that basically does the following. 1.) create a form asking for a password 2.) pass the password to a php script 3.) the php script contains an array of valid passwords 4.) compare the password entered to the passwords in the array 5.) print the password is valid or invalid depending on input I've been successful with this part the next part is where I need help 6.) If the password is invalid display the form again I have no idea how to link to the password form from the php script if the password is invalid FYI this is an intro class so it has to be "basic" programming. Thanks Link to comment https://forums.phpfreaks.com/topic/41635-looping-to-a-link-with-php-script/ Share on other sites More sharing options...
bwochinski Posted March 7, 2007 Share Posted March 7, 2007 Put it all in one file, with the PHP above the HTML form. Have the form like: <form method="POST">. Around your PHP add a check for $_POST['submit'] being set, so you know if the form has been submitted, and then do your checking. If the password is wrong, then just set an error message and let the page display again. If it's right, then redirect to a "success" page. Link to comment https://forums.phpfreaks.com/topic/41635-looping-to-a-link-with-php-script/#findComment-201816 Share on other sites More sharing options...
boo_lolly Posted March 7, 2007 Share Posted March 7, 2007 this is the way i'd do it: <?php if(!isset($_POST['password'])){ echo "<form action=\"\" method=\"post\">\n"; echo "<input type=\"text\" name=\"password\">\n"; echo "<input type=\"submit\" value=\"Submit\">\n"; echo "</form>\n"; }else{ /*set password array*/ $valid = array("password1", "password2", "password3", "password4"); /*set valid password confirm variable*/ $bool = NULL; /*upon form submit process password*/ foreach($valid as $password){ if($_POST['password'] == $password){ $msg = "<div align=\"center\"><font color=\"AAAA00\">Password is valid.</font></div><br />\n"; $bool = true; } } if($bool != true){ echo "<div align=\"center\"><font color=\"FF0000\">Password is not valid. Please try again.</font></div><br />\n"; echo "<form action=\"\" method=\"post\">\n"; echo "<input type=\"text\" name=\"password\">\n"; echo "<input type=\"submit\" value=\"Submit\">\n"; echo "</form>\n"; }else{ echo $msg; } unset($_POST); } Link to comment https://forums.phpfreaks.com/topic/41635-looping-to-a-link-with-php-script/#findComment-201880 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.