I have looked for days and I have tried many many possible solutions but nothing that I try works. The image and all of the information that is submitted is recorded in the database. It is just that the image does not show up when the information is being retrieved from the database
This is the code that I am using to add the info to the database
//check and see if the type of uploaded file is an image
function is_valid_type($file) {
$valid_types = array("image/jpg", "image/jpeg", "image/gif", "image/bmp");
if (in_array($file['type'], $valid_types))
return 1;
return 0;
}
//Set Constants
$TARGET_PATH = "/home/content/m/i/k/mikedmartiny/html/db_images/";
$title = $_POST['title'];
$year = $_POST['year'];
$make = $_POST['make'];
$model = $_POST['model'];
$descript = $_POST['descript'];
$image = $_FILES['image'];
//Sanitize the inputs
$title = mysql_real_escape_string($title);
$year = mysql_real_escape_string($year);
$make = mysql_real_escape_string($make);
$model = mysql_real_escape_string($model);
$descript = mysql_real_escape_string($descript);
$image['name'] = mysql_real_escape_string($image['name']);
//$target_path full string
$TARGET_PATH .= $image['name'];
//make sure that all fields from form are filled in
if ( $title == "" || $year == "" || $make ="" || $model == "" || $descript == "" || $image['name'] == "") {
$_SESSION['error'] = "ALL FIELDS ARE REQUIRED!";
header ("Location: show_add.php");
exit;
}
//check to make sure it has the right file type
if (!is_valid_type($image)){
$_SESSION['error'] = "You must upload a jpeg, gif, or bmp";
header ("Location: show_add.php");
exit;
}
//check to see if a file with that name exsists
if (file_exists($TARGET_PATH)){
$_SESSION['error'] = "A FILE WITH THAT NAME ALL READY EXIST!";
header ("Location: show_add.php");
exit;
}
//move the image - write path to database
if (move_uploaded_file($image['tmp_name'], $TARGET_PATH)){
$sql = "INSERT INTO $table (id, title, year, make, model, descript, image) VALUES ('', '$_POST[title]', '$_POST[year]', '$_POST[make]', '$_POST[model]', '$_POST[descript]', '" . $image['name'] . "')";
$result = mysql_query($sql) or die ("Could not insert data into DB: " . mysql_error());
} else {
// Make sure you chmod the directory to be writeable
$_SESSION['error'] = "COULD NOT UPLOAD FILE. CHECK WRITE/REWRITE PERMISSIONS ON THE FILE DIRECTORY!";
header ("Location: show_add.php");
exit;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Classified Added</title>
</head>
<body>
<div>
<h3>The following information has been added to the <?php echo "$table"; ?></h3>
<p> <strong>Title:</strong> <?php echo "$title"; ?> </p>
<p> <strong>Year:</strong> <?php echo "$year"; ?> </p>
<p> <strong>Make:</strong> <?php echo "$make"; ?> </p>
<p> <strong>Model:</strong> <?php echo "$model"; ?> </p>
<p> <strong>Description:</strong> <?php echo "$descript"; ?> </p>
<p> <strong>Image:</strong> <?php echo "<img src=\"../db_images/'$image'\">"; ?></p>
<p><a href="show_add.php">Add another classified ad</a></p>
<p><a href="admin_menu.php">Return to main menu</a></p>
This is the code output
<p> <strong>Year:</strong> 1998 </p> <p> <strong>Make:</strong> </p> <p> <strong>Model:</strong> camaro </p> <p> <strong>Description:</strong> kjhgnfbdvcscdvfbgnhmj,k.hmgnfbdvscxcdvfbgnhmj,k </p> <p> <strong>Image:</strong> <img src="../db_images/%27Array%27"></p> <p><a href="show_add.php">Add another classified ad</a></p> <p><a href="admin_menu.php">Return to main menu</a></p>
What am I doing wrong? Can someone please help me?

New Topic/Question
Reply




MultiQuote



|