2011-08-14 5 views
0

로그인을하고 있는데 MySQL 쿼리에서 행 수를 계산하는 데 오류가 있습니다. 오류는 아래와 같습니다.행 개수가 잘못되었습니다.

Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in /home/nzcraftn/public_html/bs/login.php on line 13 

Warning: Cannot modify header information - headers already sent by (output started at /home/nzcraftn/public_html/bs/login.php:13) in /home/nzcraftn/public_html/bs/login.php on line 21 

로그인 할 때이 코드를 사용하고 있습니다.

<?php 
session_start(); 
include('config.php'); 

$user = protect($_POST['username']); 
$pass = protect($_POST['password']); 

$salt = "a123b123"; 
$thepass = md5($salt.md5($pass)); 

$res = mysql_query("SELECT `username`,`password` WHERE (`username` = '$user' AND `password` = '$thepass')"); 

$count = mysql_num_rows($res); 

if($count == 1) { 
$_SESSION['user'] = $user; 
print($_SESSION['user']); 
//header('Location: /panel/index.php'); 
} else { 
$_SESSION['errormsg'] = "<div style='color: #FF0000'>Invalid Login!</div>"; 
header('Location: index.php'); 
} 
?> 
+0

이 오류는 다소 설명이 필요합니다. mysql_query는 유효한 쿼리를주지 않았기 때문에 false를 반환했다. 선택할 테이블을 지정하지 않았습니다. 'false'로 행을 셀 수 없습니다. –

+0

[mysql_fetch_array()의 복제본은 매개 변수 1이 리소스가 될 것으로 기대하고, 부울은 select에 주어진다] (http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource) -boolean-given-in-select) – legoscia

답변

2

당신은 너무 mysql_queryfalse을 반환, 귀하의 문에 오류가 있습니다. 코드에 오류 검사 (및 디버깅을위한 로깅)를 추가하십시오.

는 (귀하의 SELECTFROM 조항이 없습니다.)

1

는 SQL 쿼리를 직접하라는 메시지는 MySQL에서 그것을 실행하여 제대로 작동하는지 확인합니다. 다음과 같이 SQL 쿼리 주위에 몇 가지 문제 해결 코드를 추가하십시오.

$query = 'SELECT ...'; 
$res = mysql_query($query) or die(mysql_error()."\n".$query); 
관련 문제