Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

msqli is it wrong

$
0
0

OK so i cant log in i make it only to

 

 

if($num_rows != 1){
 

my username and password are right but i keep getting user does not exist 

i dont get erros only warnning undiefiend index but thats not probelm

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
	//start the sessoin
	session_start();
	
	//connect to db
	require "scripts/db.ini.php";
	
	$username = mysqli_real_escape_string($db,$_POST['username']);
	$password = mysqli_real_escape_string($db,$_POST['password']);

	if(isset($_POST['loginbtn'])){

	if($username && $password){
	
	//sql command
	$getstaff = "SELECT * FROM `staff` WHERE `username` = '$username'";
	
	//execute the query 
	$query = mysqli_query($db,$getstaff);
	
	//get the number of rows
	$num_rows = mysqli_num_rows($query);
	
	if($num_rows != 1){
	
	//get the info
	$rows = mysqli_fetch_assoc($query);
	
	//setting the data in indivaul variables
	$dbusername = $rows['username'];
	$dbpassword = $rows['password'];
	
	//getting the password the user enter and making it hash
	//in order for it to match in the database
	$password = md5('$password');
	
	if($dbusername === $username && $dbpassword === $password){
	
		//create the session
		$_SESSION['username'] = $usersession;
		//redircet them to the control panel
		header("location: controlpanel.php");
	
	}else
		$msg = "Please check your username or password";
	}else
		$msg = "User does not exist";
	}else
		$msg = "Please enter your username and password";
	}
?>

 

 

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles