Could use some help understanding this code

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Deewr
Forum Newbie
Posts: 2
Joined: Wed Jul 14, 2010 2:54 pm

Could use some help understanding this code

Post by Deewr »

Hello, newbie here. I just starting teaching (or trying to) myself Php. I have WAMP set up on my computer to test the codes I'm learning.
I have a simple piece of code involving a form that is not doing what the tutorial (one I found online) says it should do.

I entered the following:

Code: Select all

<html>
<head>
<title>A BASIC HTML FORM</title>

<?PHP
if (isset($_POST['Submit'])) {

$username = $_POST['username'];

if ($username=="letmein") {
print ("Welcome back, friend!");
}
else {
print ("You're not a member of this site");
}
}
?>
</head>
<body>

<FORM NAME ="form1" METHOD ="POST" ACTION = "basicForm.php">
<INPUT TYPE = "TEXT" VALUE ="username" NAME = "username">
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Login">


</FORM>
</body>
</html>


I get the submit box, but nothing happens with the if -else statements when I enter a username. No errors either, unless I remove the closing ?>, which incidentally was NOT in the original tutorial. When I left it off, I got a syntax error. Also, I got results before adding the "isset" statement. Any ideas why this code doesn't yield any results?

Thanks!
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

Re: Could use some help understanding this code

Post by yacahuma »

The name of your button is submit1 instead of submit. When you check you isset, the names most be the same
Deewr
Forum Newbie
Posts: 2
Joined: Wed Jul 14, 2010 2:54 pm

Re: Could use some help understanding this code

Post by Deewr »

Thank you. It's always something so simple and obvious, isn't it?
Post Reply