0

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?

2
Contributors
3
Replies
16
Views
3 Years
Discussion Span
Last Post by pritaeas
0

$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;
0

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....

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.