Broken Images when showing from MYSQL database

Hey there!

I have this big project due 5 days and I really need some help. I’ve made a imagesharing website where you upload images to a MySQL database into a table called images (with id, name and image)

This is the uploading form code:

[PHP]

Ladda upp här

<?php define('DB_NAME','xxxxxx'); define('DB_USER','xxxxxxxxx'); define('DB_PASSWORD','xxxxxxxx'); define('DB_HOST','xxxxxxxx.com'); //Ansluta mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die (mysql_error()); mysql_select_db(DB_NAME) or die (mysql_error()); $file= $_FILES['image']['tmp_name']; if(!isset($file)) echo "Välj en bild"; else { $image = addslashes(file_get_contents($_FILES['image']['tmp_name'])); $image_name = addslashes($_FILES['image']['name']); $image_size = addslashes(getimagesize($_FILES['image']['tmp_name'])); if($image_size==FALSE) echo "Det är ingen bild"; else { if(!$insert = mysql_query("INSERT INTO images VALUE ('','$image_name','$image')")) echo "Problem med uppladdning"; else { $lastid = mysql_insert_id(); echo "Klart!

Bilden du laddade upp:

"; } } } ?>

[/PHP]

and this is the page which I’m trying to view the images on:

[PHP]

<?php define('DB_NAME','xxxxxxx'); define('DB_USER','xxxxxxx'); define('DB_PASSWORD','xxxxxx'); define('DB_HOST','xxxxxxxxxxxxxx.com'); mysql_connect(DB_HOST, DB_USER, DB_PASSWORD) or die (mysql_error()); mysql_select_db(DB_NAME) or die (mysql_error()); $res=mysql_query("SELECT * FROM images"); echo ""; while($row=mysql_fetch_array($res)) { echo ""; echo "";

echo “

”;
echo “”;
}
echo “
";?> <?php echo " ”; echo $row[“name”]; echo “
”;
mysql_close();

?>

[/PHP]

Why do my images get broken??

Could someone please help me I’d be really happy!

Well in your img tag output you jump out of php and then back in after but you have a php var in the img tag that is not being read by php cause you are not within php tags
[php]encode($row[‘image’])">[/php]

Sponsor our Newsletter | Privacy Policy | Terms of Service