0

When I am running this query it is not returning any results. I believe there must be a syntax error as it is stopping the code from running later down the page. Anyway, I can't see where I am going wrong.

If nothing seems to be the problem with the syntax I can post my database structure, if necessary.

    $tag = $_GET['tag'];
    $stmt = $mysqli->prepare('SELECT trips.trip_id FROM tags JOIN trips ON trips.post_id = tags.post_id WHERE tag = ?');
    $stmt->bind_param('s', $tag);
    $stmt->execute();
    $stmt->bind_result($trip_id); ?>

    <div id="map_canvas<?php echo $trip_id ?>" style="height:400px;"></div><?php

Update: I have ran the error reporting script and this is what is comes out with...

Fatal error: Call to a member function bind_param() on a non-object in /Users/.../server/inc/feed-algorithm.php on line 37
David
  • 35
  • 4

1 Answers1

0

Look at PHP manual http://php.net/manual/en/mysqli.quickstart.prepared-statements.php and set up your error statements properly. Your prepare statement should look like this:

if(!$stmt = $mysqli->prepare('SELECT trips.trip_id FROM tags JOIN trips ON trips.post_id = tags.post_id WHERE tag = ?')){
    echo "Prepare failed: (" . $mysqli->errno . ") " . $mysqli->error;
}

Of course, alternatively, throw and handle exceptions if you would like to be a little more elegant and keep your errors from users.

Also follow error checking in the Example 2 section. It appears your problem is going to be in the prepare statement though because if it was successful, it would not return a 'non-object'.

Wes Grant
  • 621
  • 5
  • 11