-Edward-
10-27-2005, 04:15 PM
I'm trying to make it so my script updates a current profile with file upload information and i cannot work out why this won't work when it works for insert:
$query = "UPDATE users SET (file_name, file_size, description, upload_date) VALUES ('{$_FILES['upload']['name']}', '{$_FILES['upload']['size']}', '{$_FILES['upload']['type']}', '$d', NOW() WHERE id = '$id')";
latheesan
10-27-2005, 06:03 PM
Try this:
$query = "UPDATE users SET (file_name, file_size, description, upload_date) VALUES ('{$_FILES['upload']['name']}', '{$_FILES['upload']['size']}', '{$_FILES['upload']['type']}', '$d', 'NOW()') WHERE id = '$id'";
-Edward-
10-28-2005, 03:19 AM
I'm now getting: Error Number= 1064
here's my snippet of code:
$query = "UPDATE users SET (file_name, file_size, description, upload_date) VALUES ('{$_FILES['upload']['name']}', '{$_FILES['upload']['size']}', '{$_FILES['upload']['type']}', '$d', 'NOW()') WHERE id = '$id'";
if ($result) {
$extension = explode ('.', $_FILES['upload']['name']);
$id = mysql_insert_id();
$filename = $id . '.' . $extension[1];
////////////////////////////////////////////////////////////////////////////
// check file can be uploaded //
////////////////////////////////////////////////////////////////////////////
if (move_uploaded_file($_FILES['upload']['tmp_name'], "../uploads/$filename")) {
echo '<p>File has been uploaded successfully<p />';
} else {
echo '<p>Opps! error cannot move the file';
///////////////////////////////////////////////
// Remove the information from database //
///////////////////////////////////////////////
$query = "DELETE FROM users WHERE upload_id = $id";
$result = @mysql_query ($query);
}
} else {
echo "Error Number= ".mysql_errno();
echo '<p>Your upload failed due to a system error, please contact the webmaster if this continues';
}
fusionrays
10-28-2005, 06:17 AM
The SQL syntax for INSERT is not the same as the syntax for UPDATE.
The format UPDATE takes is as follows:
UPDATE table_name
SET
field = value, field1 = value1
WHERE condition
fusionrays
10-28-2005, 06:19 AM
For more details you cna visit
http://www.w3schools.com/sql/sql_update.asp
-Edward-
10-28-2005, 07:14 AM
Now this will teach me for coding at silly hours without coffee, thank you for pointing out what i should of remembered! I'll go change my update command.