anybody i need the codes to display image. im stucked with it. Im already done doing the codes for uploading.
see it below..
i badly need it

<?php
 // Create MySQL login values and 
// set them to your login information.
$username = "root";
$password = "";
$host = "localhost";
$database = "db1";

// Make the connect to MySQL or die
// and display an error.
$link = mysql_connect($host, $username, $password);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}

// Select your database
mysql_select_db ($database);  
// Make sure the user actually 
// selected and uploaded a file



$target_path = "images/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    //echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
$sql = "INSERT INTO tb_product (product_image)values('$target_path')";
    $result=mysql_query($sql);
mysql_close($link);
    header ('Location: viewproducts.php');
} else{
    echo "There was an error uploading the file, please try again!";
}




// Close our MySQL Link

?>

Recommended Answers

All 5 Replies

Hi

First you have to select that target path from the data base. Then you can display the image using the following code

<img src="<?=$targetpath?>"/>

$targetpath should be the path you saved in the data base

the image is already saved in the database but when i used to view it with my viewproducts script, it was not shown. only the filename

try this.

<img src='<?php echo $targetpath;?>'>

If this code don't work, maybe you can post your viewproducts script here.

guys,still doesnt worked!

How does the resulting HTML source code look?
Did you really use $targetpath as variable name, or shouldn't ir read $target_path ?

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.