Hi guys , I'm trying to set up a basic register/login PHP script.The script registers the users upon execution but doesn't log them in properly i.e. without modification it always gives you "incorrect username" no matter if you try to put in the proper one...so I tried to modify the bit of the code in line 13 to ( if ($rows=0 ) then you can put any names no matter how many times which is again incorrect.The first row in my mySQL database is "0" not 1.I tried that as well......all connection is done locally.Appreciate any comments.Thanks.
:
1. <?php
2. session_start();
3. mysql_connect("localhost", "username of your database", "password of database");
4. mysql_select_db("myDB");
5. function user_login ($username, $password)
6. {
7. //take the username and prevent SQL injections
8. $username = mysql_real_escape_string($username);
9. //begin the query
10. $sql = mysql_query("SELECT * FROM usersystem WHERE username = 'username' AND password = 'password' LIMIT 1");
11. //check to see how many rows were returned
12. $rows = mysql_num_rows($sql);
13. if ($rows<=0 )
14. {
15. echo "Incorrect username/password";
16. }
17. else
18. {
19. //have them logged in
20. $_SESSION['sername'] = $username;
21. }
22. }
23.?>
:
1. <?php
2. session_start();
3. mysql_connect("localhost", "username of your database", "password of database");
4. mysql_select_db("myDB");
5. function user_login ($username, $password)
6. {
7. //take the username and prevent SQL injections
8. $username = mysql_real_escape_string($username);
9. //begin the query
10. $sql = mysql_query("SELECT * FROM usersystem WHERE username = 'username' AND password = 'password' LIMIT 1");
11. //check to see how many rows were returned
12. $rows = mysql_num_rows($sql);
13. if ($rows<=0 )
14. {
15. echo "Incorrect username/password";
16. }
17. else
18. {
19. //have them logged in
20. $_SESSION['sername'] = $username;
21. }
22. }
23.?>