php - mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in -
already looked @ other answers couldn't fix it. monday i've got school exams , want build basic cms (add, edit, delete pages, resized images). programming knowledge beginner , don't know oop (pdo), design patterns, best practices , kind of things.
as checked query in phpmyadmin looks fine. in header include there connection included.
<?php include('inc/header.php'); if(isset($_post["submit"])) { $username = trim($_post["username"]); $password = trim($_post["password"]); $password_secure = md5($password); if($username == "") { $error++; $_session["loginerror"] = true; header("location: loginerror.php"); exit; } if($password == "") { $error++; $_session["loginerror"] = true; header("location: loginerror.php"); exit; } if($username != "" && $password != "") { $sql = "select * user username = '".$username."' , password = '".$password_secure."'"; } if(mysqli_num_rows($query == 1)) { $row = mysqli_fetch_array($query); $_session['username'] = $row["username"]; $_session['firstname'] = $row["firstname"]; $_session['lastname'] = $row["lastname"]; $_session['login'] = true; header("location: user.php"); exit; } } else { header("location: index.php"); exit; } ?>
is smart check post request $_server['request_method'] == 'post'
instead of isset() , escape sql mysql_real_escape_string
in query?
thanks
you forgot execute query
$query = mysqli_query($sql); $rowcount=mysqli_num_rows($query);
and then
if($rowcount == 1){ // ur stuff }
Comments
Post a Comment