0

Still stuck on images with php.
I want users who are logged in to see the images they uploaded. I got scripts working but the get image file is not bringing image according to specific user.
The problem seem to be in the query. I always get the first image in table instead of specific one.

<?php
if(!isset($_SESSION)){
	session_start();
}
# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_connAdmin = "localhost";
$database_connAdmin = "mystuff";
$username_connAdmin = "root";
$password_connAdmin = "dck19idea";
$connAdmin = mysql_pconnect($hostname_connAdmin, $username_connAdmin, $password_connAdmin) or trigger_error(mysql_error(),E_USER_ERROR); 
?>
<?php
$colname_Recordset1 = "-1";
if (isset($_SESSION['MM_Username'])) {
  $colname_Recordset1 = $_SESSION['MM_Username'];
}


//$id = addslashes($_REQUEST['user_id']);
$image = mysql_query("SELECT image.name, image.content, image.user_id, users.user_name, users.user_id FROM mystuff.image JOIN users WHERE users.user_name='$colname_Recordset1'");

$image = mysql_fetch_assoc($image);
$image=$image['content'];

header("Content-type: image/jpeg" );
echo $image;
?>

Again, any help is appreciated.

2
Contributors
2
Replies
3
Views
6 Years
Discussion Span
Last Post by phpDave
1

$image = mysql_query("SELECT image.name, image.content, image.user_id, users.user_name, users.user_id FROM mystuff.image JOIN users WHERE users.user_name='$colname_Recordset1'");

You're correct. The problem is with your query. You join the user table, but don't specify what fields to use for the join.

Try:

$image = mysql_query("SELECT image.name, image.content, image.user_id, users.user_name, users.user_id FROM mystuff.image JOIN users ON users.id = image.user_id WHERE users.user_name='$colname_Recordset1'");

Or whatever the primary key in your users table is called.

R.

0

Thank You! It works, I have been stuck for a while on this.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.