PDA

View Full Version : Logging in problem


FethrdWlf
03-27-2011, 05:27 PM
I am trying to follow davidj's tutorial on logging in, and it has worked so far up to the point where I need to use PHP w/ MySQL to either "...fetch_assoc" or "...fetch_array" the information from my database. Whenever I try to do that, I get this error:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\fethrdwlf\scripts\login.php on line 11

Here is my code for logging in:
1. <?php
2. include("mysql.php");
3.
4. $entereduser = $_POST['user'];
5. $pass = $_POST['pass'];
6.
7. session_start();
8.
9. $query = "SELECT FROM users WHERE (username = '$entereduser',password = '$pass')";
10. $results = mysqli_query($cxn,$query);
11. $logrow = mysqli_num_rows($results);
12. $_SESSION['id'] = $logrow['id'];
13.
14. if($logrow > 0){
15. header("Location: others/loggedin.php");
16. exit();
17. }
18.
19. ?>

Ya' know, minus the numbers I added on each line.

davidj
03-30-2011, 03:52 PM
Your SQL is wrong

SELECT * FROM........

And you don't need the brackets after the WHERE clause

And you have to use AND instead of , comma's in a SELECT statement

SELECT * FROM users WHERE username = '$entereduser' AND password = '$pass'

FethrdWlf
03-31-2011, 12:02 AM
Your SQL is wrong

SELECT * FROM........

And you don't need the brackets after the WHERE clause

And you have to use AND instead of , comma's in a SELECT statement

SELECT * FROM users WHERE username = '$entereduser' AND password = '$pass'

Yeah... I figured that out eventually. Thank you anyways!