すべての行を定義値から同じユーザー名として選択します。私は定義値からすべての行を選択してください。ユーザー名
$db->query("SELECT * FROM data WHERE username = $username")
それが働いて得るていないしようとすると、「データの取得中にエラーが発生しました」。だから、 iは
$db->query("SELECT * FROM data WHERE(username='".intval($username)."')")
で再度試して、それが検索に取り組んでいるが、私は正確に行うintval何
<?php
$response = array();
if(isset($_GET['username'])){
$username = $_GET['username'];
require_once __DIR__ . '/db_config.php';
$db = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
if(mysqli_connect_errno()){
printf("Connect failed: %S\n", mysqli_connect_error());
exit();
}
if($result = $db->query("SELECT * FROM data WHERE(username='".intval($username)."')"){
$rowCount = $result->num_rows;
if($rowCount > 0){
$response["data"] = array();
while($row = $result->fetch_assoc()){
$data = array();
$data["_id"] = $row["_id"];
$data["date"] = $row["date"];
$data["username"] = $row["username"];
$data["name"] = $row["name"];
$data["lastname"] = $row["lastname"];
$data["tel"] = $row["tel"];
array_push($response["data"], $data);
}
$response["success"]=1;
}
else{
$response["success"]=0;
$response["message"]="The database is empty.";
}
$result->close();
}
else{
$response["success"]=0;
$response["message"]="An error occurred while retrieving data.";
}
}
else{
$response["success"]=0;
$response["message"]="Required field(s) is missing.";
}
echo json_encode($response);
?>
[変数$ユーザ名は単一引用 ( ')で囲む必要があります]あなたのクエリで 'intval'を使用している理由は? –
この列名のデータ型がCharまたはVarcharであることを確認してください '$ db-> query(" SELECT * FROM data WHERE username%WHERE username% "$)"; – Sundar
"SELECT * FROMデータWHERE username = "。$ username; – JYoThI