View Full Version : PHP/MySQL Image Issues

03-17-2009, 01:28 PM
I have a free listing website that includes an image.
I have the code that inserts the text and then a seperate page that should upload an image and insert the URL into the database as an UPDATE.

The code uploads the image, but doesn't add the url to the database.
The message I recieve when testing it tells me that it has been uploaded and added to the database...which obviously it's not!

Can anyone tell me what I'm missing here?

Here is the code for the form...

<form method="post" action="addImage.php" enctype="multipart/form-data">
<table width="98%" border="0" cellspacing="4" cellpadding="0">
<td colspan="2"><input name="id" type="hidden" />
Please upload an image to compliment your listing in gif or jpeg format. The file name should be named after the with your company name. If the same file name is uploaded twice it will be overwritten! Maxium size of File is 35kb. </td>
<td width="26%">Image:</td>
<td width="74%"> <input type="hidden" name="size" value="350000">
<input type="file" name="photo"></td>
<input type="submit" name="insert_email" id="insert_email" value="Submit Image" />

Here is my PHP code...


//This is the directory where images will be saved
$target = "images/";
$target = $target . basename( $_FILES['photo']['name']);

//This gets all the other information from the form

// Connects to your Database
mysql_connect("", "CommBizGuide", "Abcd1234") or die(mysql_error()) ;
mysql_select_db("CommBizGuide") or die(mysql_error()) ;

//Writes the information to the database
mysql_query("UPDATE CommBizGuide (id, photo)
VALUES ('$id','$image')") ;

//Writes the photo to the server
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))

//Tells you if its all ok
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory";
else {

//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";

Thanks in advance for your help!!!

03-17-2009, 01:50 PM
Try changing
mysql_query("UPDATE CommBizGuide (id, photo)
VALUES ('$id','$image')") ; to

mysql_query("UPDATE CommBizGuide (id, photo)
VALUES ('$id','$image')") or die(mysql_error()) ;

03-17-2009, 03:09 PM
The syntax of your UPDATE query is not correct. Please check the manual or a good tutorial for the correct syntax - http://dev.mysql.com/doc/refman/5.0/en/update.html

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum