Forum Moderators: coopster
I'm new here, and thought I'd ask the experts about this little blip I've been having. I'm trying to write a simple script in order to check whether the submit button has been pressed, and depending on that, display certain text in the header. For my php test script, I have:
<?
$username = $_POST['username'];
if (isset($_POST['submit'])) //tests if the button has been pressed
{
if($username == "correctname"){
print(" - Welcome back, $username!");
}
else if($username!= "correctname"){
print(" - You'd better try again, $username!");
}
}
else {
print(" - Welcome!");
}
?>
The problem is, when I put in that extra if command in, then it perpetually displays me else command of " - Welcome!" in the header, even when submit is pressed.
Any ideas?
Thanks!
-Cal
Are you sure the button on your form has name="submit"?
It's case-sensitive, so if your button says name="Submit" then your if condition would always evaluate false.
Also, it would be better to put:
$username = $_POST['username'];
inside that first if (next line after your opening brace).