atticus Posted November 6, 2007 Share Posted November 6, 2007 I get the following error when trying to change image file associated with row. The image is stored on the server and the link in mysql. Error: Error, query failed : 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 '(name, size, type, path) WHERE id='7'VALUES ('album1.jpg', '38916', 'image/pjpeg' at line 1 code: $fileName = $_FILES['userfile']['name']; $tmpName = $_FILES['userfile']['tmp_name']; $fileSize = $_FILES['userfile']['size']; $fileType = $_FILES['userfile']['type']; $filePath = $uploadDir . $fileName; $result = move_uploaded_file($tmpName, $filePath); chmod($filePath, 0755); if (!$result) { echo "Error uploading file"; exit; } if(!get_magic_quotes_gpc()) { $fileName = addslashes($fileName); $filePath = addslashes($filePath); } mysql_connect($db_host, $db_user, $db_pwd); mysql_select_db($db_name); $query = "UPDATE upload2 (name, size, type, path) WHERE id='$_GET[id]'". "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')"; mysql_query($query) or die('Error, query failed : ' . mysql_error()); Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 6, 2007 Share Posted November 6, 2007 When Updating, you need to use the SET clause. $query = "UPDATE upload2 SET name = '$fileName', size = '$fileSize', type = '$fileType', path = '$filePath' WHERE id='$_GET[id]'" PhREEEk Quote Link to comment Share on other sites More sharing options...
r-it Posted November 6, 2007 Share Posted November 6, 2007 that is why i think sql should be 1, not all of this. Quote Link to comment Share on other sites More sharing options...
atticus Posted November 6, 2007 Author Share Posted November 6, 2007 thanks...but now I am getting the following error: Parse error: syntax error, unexpected T_STRING in .../.../.// line 45 line 45: mysql_query($query) or die('Error, query failed : ' . mysql_error()); Quote Link to comment Share on other sites More sharing options...
PHP_PhREEEk Posted November 6, 2007 Share Posted November 6, 2007 Sorry, bit by the semi-colon monster... better formatting helps avoid those problems.. heh $query = "UPDATE upload2 SET name = '$fileName', size = '$fileSize', type = '$fileType', path = '$filePath' WHERE id='$_GET[id]' "; PhREEEk Quote Link to comment Share on other sites More sharing options...
r-it Posted November 6, 2007 Share Posted November 6, 2007 When Updating, you need to use the SET clause. $query = "UPDATE upload2 SET name = '$fileName', size = '$fileSize', type = '$fileType', path = '$filePath' WHERE id='$_GET[id]'" PhREEEk $query = "UPDATE upload2 SET name = '".$fileName."', size = '".$fileSize."', type = '".$fileType."', path = '".$filePath."' WHERE id='$_GET[id]'" thats it, and the semi-colon Quote Link to comment Share on other sites More sharing options...
atticus Posted November 6, 2007 Author Share Posted November 6, 2007 thanks...works great...appreciate all your help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.