Closed Lande-91 closed 10 years ago
Okay that error generally means that the query has an error in it. I have not gone really deep into error handling yet in the videos soI will help you out here.
We are going to wrap another if around the mysqli_num_rows.
Your Code:
if (mysqli_num_rows($r) == 1) {
$_SESSION['username'] = $_POST['email'];
header('Location: index.php');
}
New Code:
if($r) { // If the query is successful...
if (mysqli_num_rows($r) == 1) {
$_SESSION['username'] = $_POST['email'];
header('Location: index.php');
}
} else { // If the query fails...
echo mysqli_error($dbc).'<br>'; // This will tell you if there is an error and what kind.
echo $q; // Echo out the query. If there is an error you should see it here.
}
Please post the error message if and query results.
Thanks! Alan
this is the error i get: FUNCTION lande.quote_smart does not exist SELECT * FROM users WHERE email = quote_smart('slande.91@test.com') AND password = quote_smart(SHA1('password'))
Oh okay. You are using a function called quote_smart(). That is not a function that is built in to PHP. Where is that function being created?
$q = "SELECT * FROM users WHERE email = quote_smart('$_POST[email]')
AND password = quote_smart(SHA1('$_POST[password]'))";
not sure if i have it other places
Yes. That is where it is being run. I need to know where it is being created. Since that function is not something that is built in to PHP, that means you would have had to create that function yourself. The code would look something like:
function quote_smart($string) {
// there would be more code inside here....
}
config/js.php
Could you copy/paste that function here? Then I can take a look at it.
function quote_smart ($value, $remove_whitespace = false){
if ( get_magic_quotes_gpc() ) {
$value = stripslashes($value);
}
if( is_numeric($value) && strpos($value,',') !== false ){
$value = str_replace(',','.',$value);
}
if( is_null($value) ){
$value = 'NULL';
} elseif (!is_numeric($value)) {
$value = "'" . mysql_real_escape_string($value) . "'";
}
if ( $remove_whitespace == true ) {
$value = remove_whitespace($value);
}
return $value;
}
moved it to data.php
It should work now correct? Because if it was in js.php then that function wasn't created yet at the time PHP was running $page = ......
Can you verify that it is fixed? Or are you still having an issue?
Still an issue
gonna try whitout quote
hmm, no error then but i do not get redirected to index
Okay. Try this...
Somewhere within the < body >< /body >
tags on login.php place this code:
if($_POST) {
echo '<pre>';
print_r($_SESSION);
print_r($_POST);
print_r($_GET);
print_r($page);
echo '</pre>';
}
Fill out the login form, submit it. Then copy/paste what gets echoed out to the page. If you need to hide the password, go ahead and do that.
Array ( ) Array ( [email] => slande.91@test.com [password] => password ) Array ( ) Notice: Undefined variable: page in E:\wamp\www\practice\home\admin\login.php on line 41
Okay, so your session variable is not being created. Otherwise, we would see it in that first array.
I am going to ask some silly questions now but sometimes the answer is so obvious/easy that we overlook it.
- In the database, is your password encrypted? Did you run the SHA1 function in phpMyAdmin when you created it?
- Are you sure you are putting in the correct email/password?
- Do you happen to have 2 records in the users table with the same email/password? If so then mysqli_num_rows() would not be equal to 1, it would be equal to 2 or more.
- What variable is on line 41?
Hmm, that is all I can think of at the moment.
1 yes 2 yes 3 no 4 print_r($page);
Oh, that is right. $page is on the frontend not in the backend.
ye
Still stuck:P
I think your problem is that you're trying to pass a PHP function into your SQL code.
http://stackoverflow.com/questions/2668894/php-function-within-sql-statement-syntax
So maybe:
$email = quote_smart($_POST['email']);
$password = quote_smart('$_POST[password]');
$q = "SELECT * FROM users WHERE email = $email AND password = SHA1($password)"
Haha Aly,
Great catch! That totally didn't even catch my eye! I tell ya, you can do this job for 10 years and simple stuff like that goes right past ya!
Alan
i get error when trying to login: Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in E:\wamp\www\practice\home\admin\login.php on line 13
Line 13: if (mysqli_num_rows($r) == 1) { porpably getting a false.
my login php: