我必須將兩個數組合併成單個內部Json編碼。我的代碼,將兩個數組合併成單個內部json_encode
$email = $_GET["email"];
$password = $_GET["password"];
$query = "SELECT * FROM tbl_user_login WHERE email='$email' AND password='$password' AND verification='1'";
$result = mysqli_query($c, $query) or die(mysqli_error($c));
$length = mysqli_num_rows($result);
if($length == 1)
{
$var[] = array('status'=>"success");
while($obj = mysqli_fetch_object($result))
{
$var[] = $obj;
}
echo '{"login":'.json_encode($var).'}';
}
else
{
$arr = array('status'=>"notfound");
echo '{"login":['.json_encode($arr).']}';
}
現在的結果是,
{"login":[{"status":"success"},{"login_id":"1","name":"Jithin Varghese","password":"some","phone":"","email":"[email protected]","addr":"","city":"","state":"","pincode":"0","type":"STD","verification":"1"}]}
而且需要輸出,
{"login":[{"status":"success","login_id":"1","name":"Jithin Varghese","password":"some","phone":"","email":"[email protected]","addr":"","city":"","state":"","pincode":"0","type":"STD","verification":"1"}]}
如何組合排列。我嘗試了很多。
您不能在沒有驗證的情況下在您的SQL查詢中使用用戶輸入,那麼您可以操作SQL注入攻擊。請看[準備好的語句](http://php.net/manual/de/mysqli.quickstart.prepared-statements.php) – KhorneHoly