Page 1 of 1

login script (just practicing)

Posted: Wed Feb 27, 2008 1:21 pm
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

Re: login script (just practicing)

Posted: Wed Feb 27, 2008 1:43 pm
by Mordred
isset($_POST['username']=="admin")
should be
isset($_POST['username']) && $_POST['username']=="admin"

ditto for the other

Re: login script (just practicing)

Posted: Wed Feb 27, 2008 1:53 pm
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".

Re: login script (just practicing)

Posted: Wed Feb 27, 2008 2:08 pm
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.

Re: login script (just practicing)

Posted: Wed Feb 27, 2008 2:21 pm
by dannyd
What im trying to do is ...

to post to itself. If successful redirect to another page .. or else display error.

Re: login script (just practicing)

Posted: Wed Feb 27, 2008 2:27 pm
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.

Re: login script (just practicing)

Posted: Wed Feb 27, 2008 2:37 pm
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.

Re: login script (just practicing)

Posted: Wed Feb 27, 2008 2:40 pm
by Jade
okay, try removing the if ($_POST['submit']) and see if you can see anything.

Re: login script (just practicing)

Posted: Wed Feb 27, 2008 2:40 pm
by dannyd
nevermind im a complete retard .. i put the closing form tag before the submit buttong .. duh

thanks for your help!