0

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

?>

Edited by Reverend Jim: Fixed formatting

4
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by smantscheff
0

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

0

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

0

try this.

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

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

0

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

This topic has been dead for over six months. 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.