2017-12-03 11 views
-3

ので、行数のコードを動作していない...私は考えていますコードに何が間違っているのかを教えてください。PHPのデータベースは、それが働いているように私のコードは思えません

アンドロイドスタジオからIDとユーザー名を取得したので、何度もチェックしましたが、正しいです。 idが整数であり、ユーザ名がvarchar型

ある
<?php 
require "database_init.php"; 

$restid = $_POST["_id"]; 
$username = $_POST["_username"]; 

echo "username is $username and restid is $restid "; 

$int = (int)$restid; 

$sql_query_1 = "select id from user_fav where rest_id= $int AND username='".$username."'"; 

$result = mysqli_query($conn,$sql_query_1); 

if($result) { 
    echo "the query worked"; 

    if (mysql_num_rows($result) > 0) { 
     echo "1"; 
    } else 
     echo "0"; 
} else 
    echo "the query didnt work"; 

?> 
+0

http://php.net/manual/mysqli.quickstart.prepared-statements.php – Phil

+0

クエリラインで同じ引用を使用してみてください。 "を削除するか、$ int変数に追加します:)しかし、あなたがそれを追加した場合は、 'を使用して、文字列の他の変数を探して置換しようとしていません。 – Demigod

+0

' echo "usernameは$ usernameとrestidですか?あなたが見たいと思う結果になるでしょうか? – Phil

答えて

-2
require "database_init.php"; 

$restid = (isset($_POST["_id"])) ? $_POST["_id"] : ''; 

$username = (isset($_POST["_username"])) ? $_POST["_username"] : ''; 

echo "username is {$username} and restid is {$restid}"; 

$int = (int)$restid; 

$sql_query_1 = "select id from user_fav where rest_id = '$int' AND username = '$username'"; 

$result = mysqli_query($conn, $sql_query_1); 

if($result) { 

    echo "the query worked"; 

    if (mysqli_num_rows($result) > 0) { 

     echo "1"; 

    } else { 

     echo "0"; 

    } 

} else { 

    echo "the query didn't work"; 

} 
関連する問題