Maybe I could be of some help.
Firstly, "user" in your case is considered a constant. You *could* do that, but you'd have to define it like this:
Code:
<?php
Define('USER', $_POST['user']); // note: the constant doesn't have to be capitalized, but it's good practice.
Define('PASS', $_POST['pass']); // same; sessions would be more controlling, and much easier to handle
If(IsSet($_POST['submit'])){
If(USER == 'username' && PASS == 'password'){
// Do whatever
}
ElseIf(!USER == 'username' && PASS == 'password'){
// Incorrect credentials
}
Else{
// Error / Empty credentials
}
}
Second, as I mentioned before, sessions are
much easier, and safer to work with.
(11-22-2013, 07:22 AM)Geoff Wrote: (11-22-2013, 05:51 AM)Slarek Wrote: Code:
if($username == "username" && $password == "password")
echo "You have successfully logged in";
else
echo "Incorrect sign in info";
Is there a reason you dont use braces? (or formatting?) It should be
Code:
if($username == "username" && $password == "password") {
echo "You have successfully logged in";
} else {
echo "Incorrect sign in info";
}
Yes, but he'd still need to check for the POST variable, such as in my code. Otherwise, nothing would happen.
(11-21-2013, 04:58 AM)ImMe Wrote: Code:
<?php
echo 'Account ID:';
echo '<input type="text" name="user">';
echo 'Password:';
echo '<input type="text" name="pass">';
if(user == 'username' && pass == "password") {
echo 'You have successfully logged in'
} else {
echo 'Incorrect sign in info'
}
?>
------------------------------------------------------------------
I thought this was right but I keep getting an error (specifically on line 9).
If anyone can help please do.
Thanks! :epic:
Just a helpful tip, go to
Stack Overflow for a greater understanding of what you're trying to achieve. Don't ask questions unless they're not answered, or don't have the answer you need.
Good luck.