I am attempting to retrieve data from two tables and echo the results out, the sql appears to be correct but it tells my the argument is invalid. heres my code:
// Retrieve all information related to this post
function get_post_data($post_id){
//test the connection
try{
//connect to the database
$dbh = new PDO("mysql:host=localhost;dbname=mjbox","root", "usbw");
//if there is an error catch it here
} catch( PDOException $e ) {
//display the error
echo $e->getMessage();
}
$sql = 'SELECT * FROM mjbox_images JOIN mjbox_posts USING (post_id) WHERE post_id = $post_id';
$result = $dbh->query( $sql );
foreach($result as $row):
echo $row['img_id'];
endforeach;
}
The
$post_idin your query won't be being expanded because the string is single quoted.It should work better with:
or: