Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
Thread: PHP/MySQL Image Issues
03-17-2009, 12:28 PM #1
- Join Date
- Mar 2009
- Thanked 0 Times in 0 Posts
PHP/MySQL Image Issues
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"> <p> <table width="98%" border="0" cellspacing="4" cellpadding="0"> <tr> <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> </tr> <tr> <td width="26%">Image:</td> <td width="74%"> <input type="hidden" name="size" value="350000"> <input type="file" name="photo"></td> </tr> <tr> <td> </td> <td> </td> </tr> <tr> <td> </td> <td><label> <input type="submit" name="insert_email" id="insert_email" value="Submit Image" /> </label></td> </tr> <tr> <td> </td> <td> </td> </tr> </table> </form>
//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("10.8.11.72", "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
//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";
//Gives and error if its not
echo "Sorry, there was a problem uploading your file.";
03-17-2009, 12:50 PM #2
- Join Date
- Mar 2007
- Thanked 2,223 Times in 2,210 Posts
- Blog Entries
Try changingtoCode:mysql_query("UPDATE CommBizGuide (id, photo) VALUES ('$id','$image')") ;
Code:mysql_query("UPDATE CommBizGuide (id, photo) VALUES ('$id','$image')") or die(mysql_error()) ;
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
03-17-2009, 02:09 PM #3
- Join Date
- Oct 2006
- Denver, Colorado USA
- Thanked 319 Times in 311 Posts
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
If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.