PHP array to string convertion warning inside a loop

nozha_gh Messages postés 1 Date d'inscription jeudi 13 avril 2017 Statut Membre Dernière intervention 13 avril 2017 - Modifié le 14 avril 2017 à 09:30
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 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.

2 réponses

Whismeril Messages postés 19028 Date d'inscription mardi 11 mars 2003 Statut Non membre Dernière intervention 24 avril 2024 656
14 avril 2017 à 07:30
Bonjour
ce forum est francophone, tu as donc deux possibilités:
  • reformuler ta question en Français
  • Aller sur notre site international http://ccm.net/


D'autre part, ici ou sur ccm.net, pour rendre ton code lisible, merci d'utiliser la coloration syntaxique, voir cette procédure
http://codes-sources.commentcamarche.net/faq/10686-le-nouveau-codes-sources-comment-ca-marche#balises-code
0
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 344
14 avril 2017 à 10:43
Bonjour

Phonenumbers... vu ta declarqtion cote javascript.. est un array... d'où le message d'erreur côté php.

0
Rejoignez-nous