I'm trying to get my $num_rows working. It had been working, and now it's not. Reading this site it was suggested I install MySqlnd on my server because some things like fetch_array and get_result were not working and now it's like I wish I'd never installed it. (Should I uninstall it?)
I've been trying so many variations of things to try get $num_rows working - and other functions - I don't know what is right or wrong anymore. Can you help ? The error I am getting is :
Fatal error: Call to undefined method mysqli::stmt() in /var/www/html/checkcontact.php on line 34
Line 34 is : $result = $con->stmt($query);
Here's my code :
<?php
require('dbConnect.php');
//post all contacts in my phone as a JSON array
$json = $_POST['phonenumber'];
//decode the JSON
$array = json_decode($json);
//bind
$query = "SELECT * FROM user WHERE username = ?";
$stmt = $con->prepare($query) or die(mysqli_error($con));
$stmt->bind_param('s', $phonenumber);
//for each value of phone_number in the array, call it $phonenumber
foreach ($array as $value)
{
$phonenumber = $value->phone_number;
$stmt->execute();
$result = $con->stmt($query);
//$result = $stmt->get_result();
//$stmt->store_result();
//$num_rows = $stmt->num_rows();
//$result = mysqli_query($con, $query);
if ($result->$num_rows > 0) {
// while ($row = $result->fetch_array(MYSQLI_ASSOC)) {
// while($row = mysqli_fetch_assoc($result)){
// $contact_id = $row['user_id'];
// echo $contact_id;
echo "number of phone numbers in the user table is " . $num_rows . "<br>";
}
}
?>
EDIT : Here is my dbConnect.php file, as requested :
<?php
define ('HOST', 'localhost');
define ('USER', 'bob');
define ('PASS', 'password');
define ('DB', 'mydb');
$con = NEW MySQLi("localhost", "bob", "password", "mydb");
if ($con->connect_error) {
die("Connection failed: " . $con->connect_error);
}
?>
$num_rowsmethod. Can you post the dbConnect.php file? This is where your$convariable comes from right? (Dont forget to remove passwords!)