그래서 최근에 내 데이터베이스로 PHP 로그인 시스템을 설정했고 하나의 작은 버그와 완벽하게 작동합니다. 나는 PHP에 익숙하지 않아서 오류 메시지가 무엇인지 완전히 이해하지 못해서 여기서 나를 도와주세요. 다음과 같이 코드는 다음과 같습니다PHP 로그인 시스템 버그
<?php #admin/index.php
#####[make sure you put this code before any html output]#####
//connect to server
$dbc = mysqli_connect('localhost','root','') or
die('could not connect: '. mysqli_connect_error());
//select db
mysqli_select_db($dbc, 'examples') or die('no db connection');
//check if the login form has been submitted
if(isset($_POST['go'])){
#####form submitted, check data...#####
//step 1a: sanitise and store data into vars(storing encrypted password)
$usr = mysqli_real_escape_string($dbc, htmlentities($_POST['u_name']));
$psw = SHA1($_POST['u_pass']) ; //using SHA1() to encrypt passwords
//step2: create query to check if username and password match
$q = "SELECT * FROM users WHERE name='$usr' AND pass='$psw' ";
//step3: run the query and store result
$res = mysqli_query($dbc, $q);
//make sure we have a positive result
>>>if(mysqli_num_rows($res) == 1){<<<
######### LOGGING IN ##########
//starting a session
session_start();
//creating a log SESSION VARIABLE that will persist through pages
$_SESSION['log'] = 'in';
//redirecting to restricted page
header('location:restricted.php');
} else {
//create an error message
$error = 'Wrong details. Please try again';
}
}//end isset go
?>
내가 오류 메시지가 >>> 내용 < < <로로 다스 려되는 라인을 표시했다. 오류 메시지는 다음과 같습니다
경고 : mysqli_num_rows()
매개 변수 1 mysqli_result
될 것으로 예상 줄에 /home/a7686887/public_html/index.php에 주어진 부울 26
이 일에 저를 도와주세요 것을 기억하시기 바랍니다 나는 PHP에 익숙하지 않으므로 답변이 도움이 될 것입니다. 감사!
-1 'mysql'이 아니라 'mysqli'입니다. 연결은 항상 '기능적'접근 방식의 첫 번째 인수입니다. – CodeAngry
그래서 내가하는 일은 단순히 "== 1"을 "== -1"로 변경하는 것입니까? –