php - Very Basic Password form not working -
i need when typed in nothing comes @ output. aware... l new websites , l have spent of morning trying figure out , can't round it. thank steve
requested explanation: page www........co.uk/contact.html
when l submit form text in filed or no text in field , click "submit". field empties (goes blank) page
refreshes , shows in address bar www........co.uk/contact.html#
which displays exact same content of www........co.uk/contact.html
and yes, filed still empty here on www........co.uk/contact.html#
basically refreshes page adding # on end
html:
<form name = "login" method = "post" action = "check.php" > <input type = "password" name = "pass"> <input type = "submit" value = "login" style="color:white; background: blue">     </form> php password check page
<?php if ($_post['pass'] == "pass123") { header("location: http://www.example-correct.co.uk"); } else { header("location: http://www.example-wrong.co.uk"); } ?>
if want password field filled after submission, need change form page .html .php, , redirect original form page instead of check.php.
<input type = "password" name = "pass" <?php if(isset($_post['pass'])) { echo 'value="'.$_post['pass'].'"'; } ?>> if user put in wrong password, instead of redirecting page, want show same page , produce error message, display form again can put in correct password.
this new contact.php
<?php if($_server['request_method'] == 'post') { if($_post['pass'] == 'pass123') { header('location: http://www.example-correct.co.uk'); } else { echo 'wrong pass'; } } ?> <html> <body> <form name = "login" method = "post" action = "contact.php" > <input type = "password" name = "pass" <?php if(isset($_post['pass'])) { echo 'value="'.$_post['pass'].'"'; } ?>> <input type = "submit" value = "login" style="color:white; background: blue">     </form> </body> </html> of course, echoing password after submission doesn't because it's nothing bullets (and never echo pass) example shows how it's done. can use separate form processing page , include() after submission, that's little more complicated. easier example.
edit: updated code example, fixed bug.
Comments
Post a Comment