Sinisterly
PHP Login - Printable Version

+- Sinisterly (https://sinister.ly)
+-- Forum: Coding (https://sinister.ly/Forum-Coding)
+--- Forum: PHP (https://sinister.ly/Forum-PHP)
+--- Thread: PHP Login (/Thread-PHP-Login)

Pages: 1 2 3 4 5


RE: PHP Login - The Real Slim Shady - 11-22-2013

(11-22-2013, 12:40 AM)ImMe Wrote: I think you for the help, but my issue still isn't resolved. If you could PM me an instance of the working code that would be nice. (Thank you for remembering I'm new at coding, and to this site.)

@Slarek has told you what the problem is twice now. There are no semicolons

here:
Code:
echo 'You have successfully logged in'

and here:

Code:
echo 'Incorrect sign in info'


Also, here:

Code:
if(user == 'username' && pass == "password") {
user and pass are not variables? a variable is denoted by a $ preceding the name. eg $user and $pass. however in this scenario, you also need to obtain the information from the form... so you would need to use something like $_POST['user'] to get the username from the form

...

except that your form isnt a form. your form needs form tags that specifies that it is a form such as <form method=post action=script.php></form>

Also, I would say its a whole lot more efficient to only inject PHP code when its needed, as opposed to putting HTML in echo tags, such as:

Code:
Account ID: <input type="text" name="user"> Password: <input type="text" name="pass"> <?php if(user == 'username' && pass == "password") { echo 'You have successfully logged in' } else { echo 'Incorrect sign in info' } ?>



RE: PHP Login - The Real Slim Shady - 11-22-2013

(11-22-2013, 12:40 AM)ImMe Wrote: I think you for the help, but my issue still isn't resolved. If you could PM me an instance of the working code that would be nice. (Thank you for remembering I'm new at coding, and to this site.)

@Slarek has told you what the problem is twice now. There are no semicolons

here:
Code:
echo 'You have successfully logged in'

and here:

Code:
echo 'Incorrect sign in info'


Also, here:

Code:
if(user == 'username' && pass == "password") {
user and pass are not variables? a variable is denoted by a $ preceding the name. eg $user and $pass. however in this scenario, you also need to obtain the information from the form... so you would need to use something like $_POST['user'] to get the username from the form

...

except that your form isnt a form. your form needs form tags that specifies that it is a form such as <form method=post action=script.php></form>

Also, I would say its a whole lot more efficient to only inject PHP code when its needed, as opposed to putting HTML in echo tags, such as:

Code:
Account ID: <input type="text" name="user"> Password: <input type="text" name="pass"> <?php if(user == 'username' && pass == "password") { echo 'You have successfully logged in' } else { echo 'Incorrect sign in info' } ?>



RE: PHP Login - Slarek - 11-22-2013

Here's a login which should* work, take a note that the input is not sanitized.
Code:
<!DOCTYPE html> <html> <body> <form action="phpfile.php" method="post"> Username<input type="text" name="username"><br> Password<input type="text" name="password"><br> <input type="submit" value="Send"> </form> <?php if(isset($_POST["username"], $_POST["password"]) && $_POST["username"] != "" && $_POST["password"] != "") { $username = $_POST["username"]; $password = $_POST["password"]; if($username == "username" && $password == "password") { echo "You have successfully logged in"; } else { echo "Incorrect sign in info"; } } ?> </body> </html>
(*I didn't try if this works, but it should)


RE: PHP Login - Slarek - 11-22-2013

Here's a login which should* work, take a note that the input is not sanitized.
Code:
<!DOCTYPE html> <html> <body> <form action="phpfile.php" method="post"> Username<input type="text" name="username"><br> Password<input type="text" name="password"><br> <input type="submit" value="Send"> </form> <?php if(isset($_POST["username"], $_POST["password"]) && $_POST["username"] != "" && $_POST["password"] != "") { $username = $_POST["username"]; $password = $_POST["password"]; if($username == "username" && $password == "password") { echo "You have successfully logged in"; } else { echo "Incorrect sign in info"; } } ?> </body> </html>
(*I didn't try if this works, but it should)


RE: PHP Login - The Real Slim Shady - 11-22-2013

(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"; }



RE: PHP Login - The Real Slim Shady - 11-22-2013

(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"; }



RE: PHP Login - Slarek - 11-22-2013

@Geoff
It is not compulsory when i don't have more than one "command" inside the statement.


RE: PHP Login - Slarek - 11-22-2013

@Geoff
It is not compulsory when i don't have more than one "command" inside the statement.


RE: PHP Login - The Real Slim Shady - 11-22-2013

(11-22-2013, 10:12 AM)Slarek Wrote: @Geoff
It is not compulsory when i don't have more than one "command" inside the statement.

bleh looks too much like python. That said, imo, consistency is key. what happens if you go back later and add a second statement? hm. Gonna confuse the fuck outta the kid when he changes to the code to add some more detail and it wont work lol.


RE: PHP Login - The Real Slim Shady - 11-22-2013

(11-22-2013, 10:12 AM)Slarek Wrote: @Geoff
It is not compulsory when i don't have more than one "command" inside the statement.

bleh looks too much like python. That said, imo, consistency is key. what happens if you go back later and add a second statement? hm. Gonna confuse the fuck outta the kid when he changes to the code to add some more detail and it wont work lol.