PHP array to string convertion warning inside a loop
nozha_gh
Messages postés1Date d'inscriptionjeudi 13 avril 2017StatutMembreDernière intervention13 avril 2017
-
Modifié le 14 avril 2017 à 09:30
jordane45
Messages postés38145Date d'inscriptionmercredi 22 octobre 2003StatutModérateurDernière intervention25 avril 2024
-
14 avril 2017 à 10:43
Hello i'm trying to check if phoneNumber exist in data base and then return a response but i'm getting array to sting convertion warning
Javascript code :
var c = [
{
"displayName" : "Nozha",
"phoneNumbers": ["97000000"]
},
{
"displayName": "Maher",
"phoneNumbers": ["97000000"]
}]
checkUser(c)
function checkUser(data){
$.ajax({
url : "https://nozha.000webhostapp.com/verifecontact.php",
type : "POST",
data : {"data":data},
success:function(data) {
console.log(data);
}
});
}
PHP code :
<?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);
?>
and here what i'm getting as response now it's seems that i'm not accessing the phoneNumber in the array :
<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":["97000000"],"success":false},
{"displayName":"Maher","phoneNumbers":["97000000"],"success":false}]
EDIT : Ajout des balises de code (la coloration syntaxique).
Explications disponibles ICI
Merci d'y penser dans tes prochains messages.
A voir également:
PHP array to string convertion warning inside a loop