herghost Posted April 11, 2009 Share Posted April 11, 2009 Hi all, I currently have this script which uploads an image to a database: <?php session_start(); include('include/database.php'); // Make sure the user actually // selected and uploaded a file if (isset($_FILES['image']) && $_FILES['image']['size'] > 0) { // Temporary file name stored on the server $tmpName = $_FILES['image']['tmp_name']; $userid = $_SESSION['SESS_USERID']; // Read the file $fp = fopen($tmpName, 'r'); $data = fread($fp, filesize($tmpName)); $data = addslashes($data); fclose($fp); // Create the query and insert // into our database. $sql = mysql_query("SELECT * FROM bandpic WHERE userid = '$userid'"); if(mysql_num_rows($sql) == 0) { $query = "INSERT INTO bandpic (userid, image) values ('$userid','$data')"; } else $query = "UPDATE bandpic SET userid = '$userid, image = '$data"; } $result = mysql_query($query); //Check whether the query was successful or not if($result) { header("location: member_home.php"); exit(); }else { die(mysql_error()); } ?> // Close our MySQL Link mysql_close($con); ?> However, if an image is already present I get this error: 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 'GIF89a\0D\0�\0\0\0\0\0���C����������������������������������������������������' at line 2 Any ideas? Link to comment https://forums.phpfreaks.com/topic/153576-solved-update-image-in-database/ Share on other sites More sharing options...
Goldeneye Posted April 11, 2009 Share Posted April 11, 2009 You're missing single-quotes inside your MySQL-UPDATE query. Link to comment https://forums.phpfreaks.com/topic/153576-solved-update-image-in-database/#findComment-806996 Share on other sites More sharing options...
herghost Posted April 11, 2009 Author Share Posted April 11, 2009 sheesh, would have thought i would have noticed that! Thanks Link to comment https://forums.phpfreaks.com/topic/153576-solved-update-image-in-database/#findComment-807007 Share on other sites More sharing options...
Goldeneye Posted April 11, 2009 Share Posted April 11, 2009 No problem. We all make mistakes like that sometimes. Link to comment https://forums.phpfreaks.com/topic/153576-solved-update-image-in-database/#findComment-807010 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.