Hi,
i am having trouble trying to display my image as i get the following error:
Notice: Undefined index: photo in C:\wamp\www\add.php on line 45
echo ‘<img src="/images/’.$row[‘photo’].‘" >’;
Here are my 2 files:
employeeform.html.php
<?php include_once $_SERVER['DOCUMENT_ROOT'] .
'/includes/helpers.inc.php'; ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd"
>
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Employee Form</title>
<meta http-equiv="content-type"
content="text/html; charset=utf-8" />
</head>
<body>
<form enctype="multipart/form-data" action="add.php" method="post">
Name: <input type="text" name="name" value=""> <br >
Email: <input type="text" name="email" value=""> <br >
Phone: <input type="text" name="phone" value=""> <br >
Photo: <input type="file" name="photo" value= "photo"> <br >
<input type="submit" value="add">
</form>
</body>
</html>
add.php
<?php
/**
*File name:add.php
*Date Created: 04th June 2010
*Last modified 04th June 2010
*
*/
include $_SERVER['DOCUMENT_ROOT'] . '/includes/employeedb.inc.php';
// This is the directory where images will be saved
$target = "images/";
// basename() is a php func that will return the name of the file
$target = $target . basename($_FILES['photo']['name']);
// This gets all the other information from the form
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$pic = ($_FILES['photo']['name']);
// Writes the information to the databse
//mysql_query("INSERT INTO employees VALUES('$name', '$email', '$phone', '$pic')");
$sql = mysqli_query($link, "INSERT INTO employees SET name = '$name', email = '$email', phone = '$phone', nameofphoto = '$pic'");
// Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'],$target) )
{
// Tells you if all ok
echo "The file " . basename($_FILES['photo']['name']) . "has been uploaded and your information has been added to the directory";
}
else
{
$error = "Sorry, there was a problem uploading your file";
include 'error.html.php';
}
// Retrives data from mysql
$sql = "SELECT * FROM employees";
$result = mysqli_query($link, $sql) or die(mysqli_error() );
while ($row = mysqli_fetch_array($result))
{
echo '<img src="/images/'.$row['photo'].'" >';
Echo "<b>Email:</b> ".$row['name'] . " <br>";
}
?>
The photo var has already been defined in my employeeform.html.php so why is it still being displayed that error?
Essentially, what i am trying to do is submit a picture to be stored onn my server, along with some info with it and then display the picture with the relevant info.
Please help if u can.