2

I have now spent over 3 hours trying to make this code work properly with mysqli extention in php. I already know that there is a user with userid 4 but when i try to use mysql prepared statement with [MYSQLI EXT], the code fails,and if it passes the test, i only see a blank page. Somebody please help me.

The code snipe is below in php.

<?php

//testing...
require_once('connections/connections.php');
ini_set('display_errors',true);
$received_id=4;//from the client...

function synchronize(){
    global $con, $received_id;

    $check_db=$con->prepare("SELECT FIRSTNAME,LASTNAME,USERNAME FROM SUPERDATATABLE WHERE USERID=?");
    $check_db->bind_param('i',$received_id);
    $check_db->execute();

    if($check_db->num_rows>0){
        $check_db->bind_result($first_name,$last_name,$user_name);
        $check_db->fetch();
        echo $first_name.'+'.$last_name.'+'.$user_name;
    }else{
        echo 'Sorry, but this did not work';
    }

}synchronize();
apexpals.com
  • 305
  • 1
  • 11
  • done any basic debugging, like checking if the prepare/execute actually succeeded? Unless you enabled exceptions somewhere else, all of your code simply ASSUMES that nothing could ever go wrong. – Marc B Oct 17 '16 at 17:15

1 Answers1

0

you are missing in store_results() function. please try the code below and see if it works for you but i have tested it.

<?php
//testing...
require_once('connections/connections.php');
ini_set('display_errors',true);

$received_id=4;//from the client...


function synchronize(){
    global $con, $received_id;

    $check_db=$con->prepare("SELECT FIRSTNAME,LASTNAME,USERNAME FROM SUPERDATATABLE WHERE USERID=?");
    $check_db->bind_param('i',$received_id);
    $check_db->execute();


    #typically required....
    #you are missing this statement which is required to check the length of selected rows
    $check_db->store_result();


    if($check_db->num_rows>0){
        $check_db->bind_result($first_name,$last_name,$user_name);
        $check_db->fetch();
        echo $first_name.'+'.$last_name.'+'.$user_name;
    }else{
        echo 'Sorry, but this did not work';
    }

}synchronize();
Dennisrec
  • 333
  • 2
  • 22