Hi guys,

Got a problem uploading an image to a directory and then including that directory location into the database so that I can display the image.

Here is the code I have so far.

<div id="main_right">
<?php
if ($picture)
{
?>
<img src="<?php echo "../images/teacher_photo/" . $picture ?>" alt="<?php $picture ?>" height="200" width="200">
<?php
}
else
{
?>
<form action="addimages.php" method="post" enctype="multipart/form-data">
<table border=0>
<tr><td>Select Image: </td><td><input type="file" name="image"></td></tr>
<tr> <td><input type="submit" name="Submit" value="Upload" ></td></tr>
</table>
</form>
</div>

and the addimages.php page looks like this

<?php
include("db_connect.php");
if (!isset($_FILES['image']['tmp_name'])) {
echo "";
}else{
$file=$_FILES['image']['tmp_name'];
$image= addslashes(file_get_contents($_FILES['image']['tmp_name']));
$image_name= addslashes($_FILES['image']['name']);
move_uploaded_file($_FILES["image"]["tmp_name"],"../images/teacher_photo/" . $_FILES["image"]["name"]);
$location="../images/teacher_photo" . $_FILES["image"]["name"];
$sql_photo = "INSERT INTO `person` (photo) VALUES ('&location') WHERE person_id = " .$person_id;
$save = mysql_query($sql_photo,$conn);
echo "<script type=\"text/javascript\">window.location=\"admin.php\"</script>";
}
?>

So, any idea where I am going wrong?

Recommended Answers

All 3 Replies

$sql_photo = "INSERT INTO person (photo) VALUES ('&location') WHERE person_id = " .$person_id;

Do not use an ampersand, but a dollar sign:

$sql_photo = "INSERT INTO `person` (photo) VALUES ('$location') WHERE person_id = " . $person_id;

OK, need to hit myself over the head for that mistake!

Fixed that, but now getting this error.

Could not get data: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1

Probably a silly mistake I am making, but can't seem to find it....

Show the query that is being executed. My guess is an empty $person_id

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.