2017-02-17 2 views
0

나는 PHP의 초보자입니다. 내 PHP 파일에서 다음 코드를 실행하려고하지만 데이터가 내 SQL 테이블에 동일한 항목으로 존재하지만 아무 결과 나 가져 오는 것입니다.PHP MAMP의 결과가 없습니다. MySQL 쿼리

<?php 
echo "this is the start"; 
$servername = "localhost"; 
$username = "root"; 
$password = "root"; 
$dbname = "PW3"; 
$conn = mysqli_connect($servername, $username, $password, $dbname); 

if (!$conn) { 
    echo "Unable to connect to databse"; 

    die("Connection failed: " . mysqli_connect_error()); 
} 
else { 
    echo "Connected"; 
    if(!empty($_POST["username"]) && !empty($_POST["password"])){ 

     $username=$_POST['username']; 
     //echo "$username"; 
     $sql="SELECT fullname FROM `users` WHERE username=ashish"; 
     $result1=mysqli_query($conn,$sql); 
     print_r($result1); 
     // Mysql_num_row is counting table row 
     $count=mysql_num_rows($result1); 
     echo "$count"; 
    } 
} 
echo "<br>this is the end"; 

?> 
+1

WHERE username = ashish "를 WHERE username = 'ashish'로 변경하고 이것이 도움이되는지 확인하십시오. 그렇지 않으면 반환되는 오류 메시지를 게시하십시오. – jeff

+0

@jeff : $ result1에 대한 결과를 얻지 만'echo "$ count"'에 대한 결과가 없습니다. 또한 다음과 같이 지정하고 싶습니다.'$ sql = "SELECT fullname FROM users where WHERE username = $ username"; ' 여기서 다시 결과를 가져 오지 않습니다. – CodeHunter

+0

@ashishkumar 당신은 그'print_r' 후에 아무 것도 얻지 못한다는 것을 의미합니까? 또는 "$ count"또는 0 또는 무엇인가 얻을 수 있습니까? – Albert221

답변

1

"ashish"를 인용하지 않으므로 데이터베이스는 키워드를 구문 분석하여 실패합니다. 당신은 mysql_error() 또는 PHP에서 호출 된 것을 볼 수 있어야합니다 :-)

+0

하지만 $ count "를 echo하지 않는 이유는 무엇입니까? – CodeHunter

+0

쿼리 오류가 있으므로 row_result가 NULL을 반환하므로 $ count가 비어 있습니다. – vegivamp