2014-02-23 2 views
0

저는 PHP에 비교적 익숙하지 않지만 약간 알고 있습니다. 로그인 시스템을 만들려고하는데 로그인 기능이 작동하지 않는 것 같습니다. 나는 check rows 명령을 수행하고 = 1인지 확인하지만 그것은 1이 아니라고 말합니다. "경고 : mysql_num_rows()는 매개 변수 1이 리소스, C : \ xampp에 지정된 객체가 될 것으로 예상합니다. \ htdocs \ message \ login.php 25시에 "PHP/SQL 로그인 폼 문제

나는 이것이 일치하는 값을 찾지 못했지만 데이터베이스를 확인 했으므로 사용자 이름과 비밀번호가 분명히 있음을 알고 있습니다.

도움을 주시면 감사하겠습니다.

코드는 다음과 같습니다 :

<html> 

<head> 

<title>Login - Messaging</title> 

</head> 

<body> 
<?php include "connect.php"; ?> 
<?php include "functions.php"; ?> 
<?php include "header.php"; ?> 

<div> 
<form method="post"> 
<?php 
if(isset($_POST['submit'])){ 
$username=$_POST['username']; 
$password=$_POST['password']; 
if($username === '' || $password === ''){ 
    $message="One or more of the fields are empty"; 
} else { 
    $password1=md5(hash("sha512",$password)); 
    $checklogin = mysqli_query($con,"SELECT * FROM `users` WHERE `username`='$username' AND `password`='$password1'"); 
    $check2=mysql_num_rows($checklogin); 
    if($check2==1){ 
     $message="Successful!"; 
     header("location: index.php"); 
    } else { 
     $message="Incorrect Username or Password"; 
    } 
} 
echo "<p>$message</p>"; 
} 
?> 
Username: <input type="text" name="username" /><br> 
Password: <input type="password" name="password" /><br> 
<input type="submit" name="submit" value="Login" /> 
</form> 
</div> 

</body> 

</html> 
+0

내 당신이 mysqli_ 및 mysql_로 전환 할거야? – j08691

+0

mysql_ * with mysql_i * –

+0

그게 내가 한 것처럼 보입니다. – poseidon

답변

1

당신이 mysql_i*mysql_* 혼합하고 당신이 쿼리 오류를 확인해야합니다.

변화 그 라인 :

$checklogin = mysqli_query($con,"SELECT * FROM `users` WHERE `username`='$username' AND `password`='$password1'"); 
$check2=mysql_num_rows($checklogin); 

에 :

$checklogin = mysqli_query($con,"SELECT * FROM `users` WHERE `username`='$username' AND `password`='$password1'") or die(mysqli_error($con)); 
$check2=mysqli_num_rows($checklogin); 
+0

고마워, 잘 했어! – poseidon

+0

@poseidon : 그것이 작동하면 내 대답을 수락합니다 :) –

+0

미안하지만, 방금 질문을 게시 한 후 10 분이 지났을 때 응답하지 않았고 신속하게 대답했습니다 (다시 감사드립니다! : D). - 내가 받아 들일 테니! – poseidon