| | |
Log In Script Problem
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jul 2008
Posts: 44
Reputation:
Solved Threads: 1
Hello, I've been using a book to learn php, and when I try to make it work for my own use, there seems to be an error when I try to login. First it says that the log in is invalid, and it comes up with this warning message:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\Program Files\wamp\www\loginsite\login.php on line 25
I can post more code if I need to
Thanks
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\Program Files\wamp\www\loginsite\login.php on line 25
php Syntax (Toggle Plain Text)
if (!empty($user_username) && !empty($user_password)) { // Look up the username and password in the database $query = "SELECT user_id, username FROM mismatch_user WHERE username = '$user_username' AND password = SHA('$user_password')"; $data = mysqli_query($dbc, $query); //below is line 25 of code if (mysqli_num_rows($data) == 1) { // The log-in is OK so set the user ID and username session vars (and cookies), and redirect to the home page $row = mysqli_fetch_array($data); $_SESSION['user_id'] = $row['user_id'];
I can post more code if I need to
Thanks
Last edited by phouse512; Oct 27th, 2009 at 9:32 pm.
•
•
Join Date: Sep 2009
Posts: 557
Reputation:
Solved Threads: 64
0
#3 Oct 28th, 2009
think of using -
if (mysqli_num_rows($data) !=0 || mysqli_num_rows($data)!=FALSE)
{
}
if (mysqli_num_rows($data) !=0 || mysqli_num_rows($data)!=FALSE)
{
}
"The discipline of writing something down is the first step towards making it happen."
follow me on twitter
follow me on twitter
•
•
Join Date: Jul 2008
Posts: 44
Reputation:
Solved Threads: 1
0
#5 Oct 28th, 2009
Froger93: I don't understand what you really mean. Could you explain a little more?
Network18: I tried replacing the line with what you did, but I still got two errors this time:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\Program Files\wamp\www\loginsite\login.php on line 25
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\Program Files\wamp\www\loginsite\login.php on line 25
But they appear to be the same.
EDIT: I fixed the error because of a stupid mistake, but now, I still can't login, when I inputed the username/password myself using MySQL console.
Network18: I tried replacing the line with what you did, but I still got two errors this time:
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\Program Files\wamp\www\loginsite\login.php on line 25
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\Program Files\wamp\www\loginsite\login.php on line 25
But they appear to be the same.
EDIT: I fixed the error because of a stupid mistake, but now, I still can't login, when I inputed the username/password myself using MySQL console.
Last edited by phouse512; Oct 28th, 2009 at 4:24 pm.
•
•
Join Date: Sep 2009
Posts: 38
Reputation:
Solved Threads: 4
0
#6 Oct 29th, 2009
Mine and networks solutions do the same thing but make sure you use the @ infront of the num_rows functions incase the query didn't return any rows, this is most likely happening because the query didn't return any results.
As I said before try inputing data into the form that you know really does exist in your database.
As I said before try inputing data into the form that you know really does exist in your database.
•
•
Join Date: Sep 2009
Posts: 557
Reputation:
Solved Threads: 64
0
#7 Oct 29th, 2009
its fine and using @ in front of the mysql_num_rows() will supress any warning you getting.
"The discipline of writing something down is the first step towards making it happen."
follow me on twitter
follow me on twitter
•
•
Join Date: Jul 2008
Posts: 44
Reputation:
Solved Threads: 1
0
#8 Nov 1st, 2009
I tried what you just said, but it still does not work. To show you, here is the data for the database, but I don't know why it won't work:
mysql> select * FROM login;
+---------+---------------+-------------+--------+
| user_id | username | password | name |
+---------+---------------+-------------+--------+
| 1 | phouse512 | ---------- | Philip |
| 2 | admin | admin | admin|
+---------+---------------+-------------+--------+
2 rows in set (0.00 sec)
Here's the login code:
mysql> select * FROM login;
+---------+---------------+-------------+--------+
| user_id | username | password | name |
+---------+---------------+-------------+--------+
| 1 | phouse512 | ---------- | Philip |
| 2 | admin | admin | admin|
+---------+---------------+-------------+--------+
2 rows in set (0.00 sec)
Here's the login code:
php Syntax (Toggle Plain Text)
<?php require_once('connectvars.php'); // Start the session session_start(); // Clear the error message $error_msg = ""; // If the user isn't logged in, try to log them in if (!isset($_SESSION['user_id'])) { if (isset($_POST['submit'])) { // Connect to the database $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); // Grab the user-entered log-in data $user_username = mysqli_real_escape_string($dbc, trim($_POST['username'])); $user_password = mysqli_real_escape_string($dbc, trim($_POST['password'])); if (!empty($user_username) && !empty($user_password)) { // Look up the username and password in the database $query = "SELECT user_id, username FROM login WHERE username = '$user_username' AND password = SHA('$user_password')"; $data = mysqli_query($dbc, $query); if (@mysqli_num_rows($data) == 1) { // The log-in is OK so set the user ID and username session vars (and cookies), and redirect to the home page $row = mysqli_fetch_array($data); $_SESSION['user_id'] = $row['user_id']; $_SESSION['username'] = $row['username']; setcookie('user_id', $row['user_id'], time() + (60 * 60 * 24 * 30)); // expires in 30 days setcookie('username', $row['username'], time() + (60 * 60 * 24 * 30)); // expires in 30 days $home_url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']) . '/index.php'; header('Location: ' . $home_url); } else { // The username/password are incorrect so set an error message $error_msg = 'Sorry, you must enter a valid username and password to log in.'; } } else { // The username/password weren't entered so set an error message $error_msg = 'Sorry, you must enter your username and password to log in.'; } } } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Mismatch - Log In</title> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body> <h3>Mismatch - Log In</h3> <?php // If the session var is empty, show any error message and the log-in form; otherwise confirm the log-in if (empty($_SESSION['user_id'])) { echo '<p class="error">' . $error_msg . '</p>'; ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>"> <fieldset> <legend>Log In</legend> <label for="username">Username:</label> <input type="text" name="username" value="<?php if (!empty($user_username)) echo $user_username; ?>" /><br /> <label for="password">Password:</label> <input type="password" name="password" /> </fieldset> <input type="submit" value="Log In" name="submit" /> </form> <?php } else { // Confirm the successful log-in echo('<p class="login">You are logged in as ' . $_SESSION['username'] . '.</p>'); } ?> </body> </html>
-1
#9 Nov 1st, 2009
PHP Syntax (Toggle Plain Text)
$data = mysqli_query($dbc, $query);
Should this be:
PHP Syntax (Toggle Plain Text)
$data = mysqli_query($query, $dbc);
Having not used mysqli - I can't comment, but I think the first parameter should be the query, then the connection link identifier.
If you don't reply to your own thread or you can't find the solved link - you're off my Christmas list - permanently! Bah humbug!
1
#10 Nov 1st, 2009
•
•
•
•
PHP Syntax (Toggle Plain Text)
$data = mysqli_query($dbc, $query);
Should this be:
PHP Syntax (Toggle Plain Text)
$data = mysqli_query($query, $dbc);
Having not used mysqli - I can't comment, but I think the first parameter should be the query, then the connection link identifier.

http://www.php.net/manual/en/mysqli.query.php
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
![]() |
Similar Threads
- Convert shell script for looping (Shell Scripting)
- simple ajax script problem (JavaScript / DHTML / AJAX)
- hjt log and a related problem (Viruses, Spyware and other Nasties)
- My HJT log - desktop problem (Viruses, Spyware and other Nasties)
- IE opens by itself and other problems, hijack log included (Viruses, Spyware and other Nasties)
- Email piping to script problem (PHP)
- log in script saves cookie (JavaScript / DHTML / AJAX)
- Hacktool.Rootkit problem (Viruses, Spyware and other Nasties)
- hijack this log:Please help diagnose problem (Viruses, Spyware and other Nasties)
- Script problems with IE (Web Browsers)
Other Threads in the PHP Forum
- Previous Thread: Search string is too exact help
- Next Thread: Is the a correct url regex?
Views: 581 | Replies: 13
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl customizableitems database date development directory display download dynamic echo email error file files folder form forms forum function functions google headmethod href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail malfunctioning menu methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web xml youtube






