php - my query doesn't work -
i making login script connected database
"undefined variable: dbusername in f:\xamp\register\login\functions.php on line 21"
i have further checked , saw query doesn't work can guys me?
if (isset($_post['sub'])) { include_once("connect.php"); $username = strip_tags($_post['username']); $password = strip_tags($_post['password']); $sql = "select id, username, password login username = '$username' limit 1"; $query = mysqli_query($dbcon, $sql); if ($query) { $row = mysqli_fetch_row($query); $userid = $row[0]; $dbusername = $row[1]; $dbpassword = $row[2]; } if ($username == $dbusername && $password == $dbpassword) { $_session['username'] = $username; $_session['id'] = $userid; header('location: login.php'); } else { echo "incorrect username or password."; } }
you need use condition inside if($query)
, dont think there need recheck because checking in query where username = $username.
have modified code as:
modified code:
$sql = "select id, username, password login username = '$username' limit 1"; $query = mysqli_query($dbcon, $sql); if (!$query) { die(mysqli_error($dbcon)); } else { $count = mysqli_num_rows($query); // check total no of rows if ($count > 0) { session_start(); // start session $row = mysqli_fetch_row($query); $userid = $row[0]; // userid database $dbusername = $row[1]; // username database $_session['username'] = $dbusername; $_session['id'] = intval($userid); header('location: login.php'); die(); // using die() after header() } else{ echo "incorrect username or password."; // if query not return print this. } }
Comments
Post a Comment