Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

197
Visualizações
Fatal error: Call to a member function bind_param() on a non-object, JSON Array

I've searched this here and on the internet but can't find a solution.

I'm posting a JSON array like :

[{"phone_number":"+12345678"},
 {"phone_number":"+23456789"},
 {"phone_number":"34567890"},
 {"phone_number":"45678901"} 
 etc... etc...

Here's my code :

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require('dbConnect.php');

//post all contacts in my phone as a JSON array
$json = $_POST['phonenumber'];
$array = json_decode($json);

    foreach ($array as $value)
    {
        $phonenumber = $value->phone_number;

$stmt = $con->prepare('SELECT * FROM user WHERE username = ?');
$stmt->bind_param('s', $phonenumber);
$stmt->execute(); 
echo $phonenumber . "<br>";
var_dump($stmt);
}
?>

Only the first phone number in the array echos properly. Then I get :

object(mysqli_stmt)#131 (10) { ["affected_rows"]=> int(-1) ["insert_id"]=> int(0) ["num_rows"]=> int(0) ["param_count"]=> int(1) ["field_count"]=> int(2) ["errno"]=> int(0) ["error"]=> string(0) "" ["error_list"]=> array(0) { } ["sqlstate"]=> string(5) "00000" ["id"]=> int(1) } 
Fatal error: Call to a member function bind_param() on a non-object in /var/www/html/checkcontact.php on line 28

Line 28 is : $stmt->bind_param('s', $phonenumber);

When I use this code (not safe though) it works fine, all the phone numbers get echoed correctly :

<?php

ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require('dbConnect.php');

//post all contacts in my phone as a JSON array
$json = $_POST['phonenumber'];
$array = json_decode($json);

    foreach ($array as $value)
    {
        $phonenumber = $value->phone_number;

                $sql = "SELECT * FROM user WHERE username = '$phonenumber'";
        $result = mysqli_query($con, $sql);


echo $phonenumber . "<br>";

    } 
        ?>
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda