0

Anyone help me to find the alternative code for my script because it requires Mysqlnd and many online servers don't have this so if I use this code It will give me this error

Fatal error: Call to undefined method mysqli_stmt::get_result()

So I want someone to change my code into mysqli version.

My Code:

  $page_id = mysqli_real_escape_string($con, $page_id);

$select_query = $con->prepare("select ID, Title, image, Cost, Vid, content from mobs where ID=?"); 

$select_query->bind_param('i', $page_id);

$select_query->execute();

$result = $select_query->get_result();

while ($row = mysqli_fetch_array($result, MYSQL_ASSOC))

{
    $post_id = $row['ID']; 
    $post_title = $row['Title'];

Update 1

if(isset($_GET['ID'])){

$page_id = $_GET['ID'];

      $page_id = mysqli_real_escape_string($con, $page_id);

$select_query = $con->prepare("select ID, Title, image, Cost, Vid, content from mobs where ID=?"); 
$select_query->execute();
$select_query->bind_result($post_id, $post_title, $post_image, $post_cost, $post_vid, $post_cont);

while ($select_query->fetch()) {      


    $post_id = $row['ID']; 
    $post_title = $row['Title'];
    $post_image = $row['image'];
    $post_cost = $row['Cost'];
        $post_vid = $row['Vid'];
            $post_cont= $row['content'];

    $sign = '$';
        $sign = mysql_real_escape_string($sign);


?>

Update 3

if(isset($_GET['ID'])){

$page_id = $_GET['ID'];



$select_query = ("select ID, Title, image, Cost, Vid, content from mobs where ID=?"); 

$select_query->execute();
$select_query->bind_result($post_id, $post_title, $post_image, $post_cost, $post_vid, $post_content);

while ($select_query->fetch())
 echo 'Post ID:', $post_id, '<br>',
         'Post title: ', $post_title;
 {
user3423422
  • 23
  • 2
  • 8

1 Answers1

0

mysqli_stmt::get_result is only available in PHP >= 5.3.0.

I suggest using bind_result instead.

Also, you don't need to escape any strings used in bind_param.

$select_query->execute();
$select_query->bind_result($post_id, $post_title, $post_image, $post_cost, $post_vid, $post_content);

while ($select_query->fetch()) {
    // do stuff with the bound result variables, eg
    echo 'Post ID:', $post_id, '<br>'
         'Post title: ', $post_title;
}
Phil
  • 157,677
  • 23
  • 242
  • 245
  • After doing this it is giving me this error `Notice: Undefined variable: select line 18` `Fatal error: Call to a member function bind_result() on a non-object` – user3423422 Mar 20 '14 at 04:19
  • @user3423422 Just a typo. Fixed now – Phil Mar 20 '14 at 04:22
  • I fixed that but now nothing is showing :D check the update plz – user3423422 Mar 20 '14 at 04:29
  • @user3423422 Again, stop using `mysqli_real_escape_string` and **especially** `mysql_real_escape_string`. You **do not need them**. I wouldn't expect anything to show as you aren't *showing* anything – Phil Mar 20 '14 at 04:30
  • @user3423422 Also, there is no `$row` variable. `bind_result` assigns values directly to your variables. You don't need `$post_id = $row['ID']` and the rest – Phil Mar 20 '14 at 04:32
  • it is not printing any result it's just blank what does it mean?? – user3423422 Mar 20 '14 at 06:02
  • @user3423422 Could be any of a number of things; invalid query, no results for the ID provided, syntax error (your latest update) – Phil Mar 20 '14 at 21:38