login script (just practicing)

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
dannyd
Forum Commoner
Posts: 56
Joined: Wed Jan 23, 2008 11:31 am

login script (just practicing)

Post by dannyd »

Code: Select all

<?PHP
 
if (isset($_POST['submit']) && isset($_POST['username']=="admin")) && isset($_POST['password']=="admin")) { 
 
   echo 'success';
}
?>
<html><body>
<table width="980" height="500"><tr valign="middle"><td align="center">
<form method="post" action="http://zenit.senecac.on.ca/~php701_081sa20/assn1/login.php"><b>User Name:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="text" name="username" size="20">
<b>Password:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="password" size="20"></form>
<input type="submit" value="submit" name="submit"></td></tr></table>
</body></html>
<?PHP
 
else {
    
    echo "Login error. Please log in again.";
   
 
}
?>  
Whats wrong with my code .. I get this error:


Parse error: syntax error, unexpected T_IS_EQUAL, expecting ',' or ')' in /.automount/server1/export/home/php701_081sa20/public_html/login.php on line 3
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Re: login script (just practicing)

Post by Mordred »

isset($_POST['username']=="admin")
should be
isset($_POST['username']) && $_POST['username']=="admin"

ditto for the other
dannyd
Forum Commoner
Posts: 56
Joined: Wed Jan 23, 2008 11:31 am

Re: login script (just practicing)

Post by dannyd »

Code: Select all

<?PHP
     
    if (isset($_POST['submit']) && isset($_POST['username']) && $_POST['username']=="admin" && isset($_POST['password']) && $_POST['password']=="admin") {
     
       echo 'success';
    }
    ?>
    <html><body>
    <table width="980" height="500"><tr valign="middle"><td align="center">
   <form method="post" action="http://zenit.senecac.on.ca/~php701_081sa20/assn1/login.php"><b>User Name:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   <input type="text" name="username" size="20">
   <b>Password:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="password" size="20"></form>
   <input type="submit" value="submit" name="submit"></td></tr></table>
   </body></html>
Not sure if I got it right but it doesnt submit to get the "success".
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: login script (just practicing)

Post by Jade »

Is http://zenit.senecac.on.ca/~php701_081s ... /login.php the page this code is on? Otherwise you might be posting it to some other page and therefore aren't seeing the success message.
dannyd
Forum Commoner
Posts: 56
Joined: Wed Jan 23, 2008 11:31 am

Re: login script (just practicing)

Post by dannyd »

What im trying to do is ...

to post to itself. If successful redirect to another page .. or else display error.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: login script (just practicing)

Post by Jade »

Have you tried simplifying it? Try changing the success message to something like this:

Code: Select all

 
<?php
if ($_POST['submit'])
{
echo "submit is: " . $_POST['submit'] . "<br/>
        username is: " . $_POST['username'] . "<br/>
        password is: " . $_POST['password'] . " <br/>";
}
?>
 
At least this way you'd know your getting the values you entered into the input fields.
dannyd
Forum Commoner
Posts: 56
Joined: Wed Jan 23, 2008 11:31 am

Re: login script (just practicing)

Post by dannyd »

Code: Select all

<?PHP
     
 
 if (isset($_POST['submit']))
 {
 echo "submit is: " . $_POST['submit'] . "<br/>";
         echo "username is: " . $_POST['username'] . "<br/>";
         echo "password is: " . $_POST['password'] . " <br/>";
 }
 ?>
    <html><body>
    <table width="980" height="500"><tr valign="middle"><td align="center">
   <form method="post" action="http://zenit.senecac.on.ca/~php701_081sa20/assn1/login.php"><b>User Name:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
   <input type="text" name="username" size="20">
   <b>Password:</b>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<input type="text" name="password" size="20"></form>
   <input type="submit" value="submit" name="submit"></td></tr></table>
   </body></html>
I get absolutely nothing when I hit submit. Strange.
User avatar
Jade
Forum Regular
Posts: 908
Joined: Sun Dec 29, 2002 5:40 pm
Location: VA

Re: login script (just practicing)

Post by Jade »

okay, try removing the if ($_POST['submit']) and see if you can see anything.
dannyd
Forum Commoner
Posts: 56
Joined: Wed Jan 23, 2008 11:31 am

Re: login script (just practicing)

Post by dannyd »

nevermind im a complete retard .. i put the closing form tag before the submit buttong .. duh

thanks for your help!
Post Reply