-2

Getting error on my code can any one tell me what I am doing wrong and how to solve it or any one suggest me the more simple code after select query because I don't want to mess my code and it is not helping

Here is my Code

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

$page_id = $_GET['ID'];

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

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

$stmt = $con->stmt_init();
if(!$stmt->prepare($select_query))
{
    print "Failed to prepare statement\n";
}   
else
{
    $stmt->bind_param("s", $page_id);

    {
        $stmt->execute();
        $result = $stmt->get_result();
if($result === FALSE) {
    die(mysql_error()); 
}

while($row->mysqli_fetch_array($result))

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

I am getting these errors

Notice: Undefined variable: row in 

Fatal error: Call to a member function mysqli_fetch_array() on a non-object 
user3423422
  • 23
  • 2
  • 8

3 Answers3

3

You're (incorrectly) combining the procedural and OOP-style calls. See mysqli_result::fetch_array.

The correct object-oriented style call:

while($row = $result->fetch_array())
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
  • @user3423422 You're welcome. Please remember to up-vote all answers that helped, and accept the one that ultimately solved your problem. – Jonathon Reinhart Mar 26 '14 at 02:40
0

Change the while statement to

**while($row=$result->fetch_array())**

Hope that helps.

Amit
  • 3,251
  • 3
  • 20
  • 31
0

$row is not an object. So you have got this error:

Call to a member function mysqli_fetch_array() on a non-object 

in this line:

while($row->mysqli_fetch_array($result))

Should be :

while($row= $result->fetch_array())

Another thing: in this bind it seems that id is integer.

$stmt->bind_param("s", $page_id);

if so then it should be:

$stmt->bind_param("i", $page_id);
Awlad Liton
  • 9,366
  • 2
  • 27
  • 53