你好,我想檢查是否phoneNumber的在數據庫中存在,然後返回一個響應,但我越來越陣列蜇皈依警告PHP數組字符串皈依警告在循環中
Javascript代碼:
var c = [
{
"displayName" : "Nozha",
"phoneNumbers": ["97925955"]
},
{
"displayName": "Maher",
"phoneNumbers": ["97925955"]
}]
checkUser(c)
function checkUser(data){
//hne 3ayet lel service php mte3ek w na7i return false
$.ajax({
url : "https://nozha.000webhostapp.com/verifecontact.php",
type : "POST",
data : {"data":data},
success:function(data) {
console.log(data);
}
});
}
PHP代碼:
<?php
$S = $_POST['data'];
for($i=0; $i<COUNT($S);$i++){
$result=mysqli_query($con,"SELECT * from user where tel='$S[$i]['phoneNumbers']'");
if(mysqli_num_rows($result)>0){
$S[$i]['success'] = true;
}else{
$S[$i]['success'] = false;
}
}
echo json_encode($S);
?>
和這裏就是我得到的迴應現在它似乎我不是數組中訪問電話號碼:
<br />
<b>Notice</b>: Array to string conversion in
<b>/storage/h2/007/664007/public_html/verifecontact.php</b> on line <b>9</b>
<br />
<br />
<b>Warning</b>: mysqli_num_rows() expects parameter 1 to be mysqli_result,
boolean given in <b>/storage/h2/007/664007/public_html/verifecontact.php</b> on line <b>10</b><br />
<br />
<b>Notice</b>: Array to string conversion in
<b>/storage/h2/007/664007/public_html/verifecontact.php</b> on line <b>9</b>
<br />
<br />
<b>Warning</b>: mysqli_num_rows() expects parameter 1 to be mysqli_result,
boolean given in <b>/storage/h2/007/664007/public_html/verifecontact.php</b>
on line <b>10</b><br />
[{"displayName":"Nozha","phoneNumbers":["97925955"],"success":false},
{"displayName":"Maher","phoneNumbers":["97925955"],"success":false}]
[小博](http://bobby-tables.com/)說***腳本是在對SQL注入攻擊的風險。( http://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php)***瞭解[製備](http://en.wikipedia.org/wiki/Prepared_statement )[MySQLi]的聲明(http://php.net/manual/en/mysqli.quickstart.prepared-statements.php)。即使[轉義字符串](http://stackoverflow.com/questions/5741187/sql-injection-that-gets-around-mysql-real-escape-string)是不安全的! –
可能有用,知道在哪裏_並看到完整的錯誤消息_ – RiggsFolly
你有什麼警告/錯誤? – borracciaBlu