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
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.