rmail2006 Posted April 30, 2009 Share Posted April 30, 2009 Im trying to upload an image to my server and then copy information to a MySQL database. this is my code that isnt working. <html> <head> <title>Uploading...</title> </head> <body> <h1>Uploading file...</h1> <?php include_once("./include/config.php"); db_connect(); if ($_FILES['userfile']['error'] > 0) { echo 'Problem: '; switch ($_FILES['userfile']['error']) { case 1: echo 'File exceeded upload_max_file_size'; break; case 2: echo 'File exceeded max_file_size'; break; case 3: echo 'File only partially uploaded'; break; case 4: echo 'No File Uploaded'; break; } exit; } // Does the file have the right MIME type? //Put the file where we'd like it $upfile = './images/'.time().$_FILES['userfile']['name'] ; $tmpfile = $_FILES['userfile']['tmp_name'] ; $imgloc = $_POST['imglocation']; echo $upfile; echo '<br /><b>'; echo $imgloc; echo '</b><br />'; if (is_uploaded_file($tmpfile)) { if (!move_uploaded_file($tmpfile, $upfile)) { echo 'Could not move file to destination'; exit; } } else { echo 'Possible File Upload Attack. Filename: '; echo $_FILES['userfile']['name']; exit; } $date = date("Y-m-d"); $sqlresult = mysql_query ("INSERT INTO `photos` (photo_title, photo_desc, photo_date, photo_location) VALUES ('$upfile', '1', '$date', '$imgloc'"); if (!$sqlresult){ die('<br />Invalid Query: ' . mysql_error()); }; echo '<div align="center">'; echo 'File uploaded successfully<br /><br />'; echo '<b>Preview: </b><br />'; echo '<img border="2" src="'.$upfile.'" width="30%" >'; echo '</div>'; ?> </body> </html> can n e 1 help plz ? Link to comment https://forums.phpfreaks.com/topic/156247-mysql-query-error-in-php/ Share on other sites More sharing options...
Potatis Posted April 30, 2009 Share Posted April 30, 2009 Do you get an error message? Link to comment https://forums.phpfreaks.com/topic/156247-mysql-query-error-in-php/#findComment-822538 Share on other sites More sharing options...
rmail2006 Posted April 30, 2009 Author Share Posted April 30, 2009 yeh... it says Invalid query: you have an error in your sql syntax; chec the manual that corresponds to your mysql server version for the right syntax to use near '' at line 1. thnx for the reply Link to comment https://forums.phpfreaks.com/topic/156247-mysql-query-error-in-php/#findComment-822544 Share on other sites More sharing options...
mrMarcus Posted April 30, 2009 Share Posted April 30, 2009 move the " outside the ), ie. $sqlresult = mysql_query ("INSERT INTO `photos` (photo_title, photo_desc, photo_date, photo_location) VALUES ('$upfile', '1', '$date', '$imgloc')"); you should use an editor with syntax highlighting .. will help you to track these problems. Link to comment https://forums.phpfreaks.com/topic/156247-mysql-query-error-in-php/#findComment-822549 Share on other sites More sharing options...
Potatis Posted April 30, 2009 Share Posted April 30, 2009 Change this line: $sqlresult = mysql_query ("INSERT INTO `photos` (photo_title, photo_desc, photo_date, photo_location) VALUES ('$upfile', '1', '$date', '$imgloc'"); To this: $sqlresult=mysql_query("INSERT INTO photos (photo_title, photo_desc, photo_date, photo_location) VALUES ('$upfile', '1', '$date', '$imgloc')"); Edit: Oops, too late. Link to comment https://forums.phpfreaks.com/topic/156247-mysql-query-error-in-php/#findComment-822551 Share on other sites More sharing options...
rmail2006 Posted April 30, 2009 Author Share Posted April 30, 2009 Thanx alot. Wors perfect nw ;D Link to comment https://forums.phpfreaks.com/topic/156247-mysql-query-error-in-php/#findComment-822556 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.