Jump to content

[SOLVED] mysql update problem


atticus

Recommended Posts

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());

Link to comment
https://forums.phpfreaks.com/topic/76255-solved-mysql-update-problem/
Share on other sites

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.