i have read many topics considering this matter, but i still have the same problem.I cant understand the logic yet i think.
so i have an image stored in one of my folders in my system and i also have the image's path registered in my database.i simply want to allow users to insert image's title to a searching form and after they press OK, i want the specific image to be displayed.
so far i have found codes like: echo '';
and they work fine for other people, but not for me
my code is the following :
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("photoshare", $con);
$Title = $_POST['Title'];
$Creator = $_POST['Creator'];
$result = mysql_query("SELECT path FROM images WHERE Title = '$Title' OR Creator = '$Creator'");
echo '<img src="' . $result . '" />';
//some code
mysql_close($con);
?>
so the problem is that no image is beign displayed.on the other hand, the icon of broken image is being displayed. if i got it right the error occurs cause i dont put what my HTTP must see or something like that.i really havent undersand it yet.
any help would be appreciated :)
Thank you both but same thing happens :/ my upload file is the following, i hope it helps :
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("photoshare", $con);
$Image_Title = $_POST['Image_Title'];
$Image_Creator = $_POST['Image_Creator'];
$Image_Date = $_POST['Image_Date'];
$Image_Genre = $_POST['Image_Genre'];
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/pjpeg"))
&& ($_FILES["file"]["size"] < 50000000))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
if (file_exists("../photo_album/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"../photo_album/" . $_FILES["file"]["name"]);
echo "Stored in: " . "../photo_album/" . $_FILES["file"]["name"];
$path = "photo_album/" . $_FILES["file"]["name"];
$query = "INSERT INTO images (title, creator, date, genre, path)
VALUES ('$Image_Title', '$Image_Creator', '$Image_Date', '$Image_Genre', '$path')";
}
}
}
else
{
echo "Invalid file";
}
if (!mysql_query($query, $con)) {
die("Error " . mysql_error());
}
?>
mysql_fetch_assoc()ormysql_fetch_array(), consider using methods likeprint_r()andvar_dump()if you are beginning with PHP for debugging and also use tools like firebug to lighten your work related to the front end..pathcolumn and see where it points? Also, is the script that shows the image in the same directory as the photo_album directory? You might need to change your path to have a../