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.

Recommended Answers

All 2 Replies

$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.

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.