Jump to content

[SOLVED] Still can't get this 'on duplicate key update' to work


pcbguy

Recommended Posts

I tried to use it and it gives me the "file has been uploaded message" from the bottom but when I check my database nothing has changed.

 

The help here has been awesome. Thanks everyone for your help so far.

 

The 'position' is the only unique key and is also the primary key.

 

<?php

//This is the directory where the images will be saved
$target="images/";
$target=$target.basename($_FILES['picture']['name']);

//This gets all the other information from the form
$position=$_POST['position'];
$year=$_POST['year'];
$make=$_POST['make'];
$model=$_POST['model'];
$price=$_POST['price'];
$description=$_POST['description'];
$picture=($_FILES['picture']['name']);

//Connects to Database
include "connect.php";

//Writes the information to the database
$query = "INSERT INTO for_sale (position,year,make,model,price,description,picture)
                      VALUES ('$position','$year','$make','$model','$price','$description','$picture')
          ON DUPLICATE KEY UPDATE
                      year='$year', make='$make', model='$model',
                      price='$price', description='$description', picture='$picture'";
mysql_query($query);

//Writes photo to the server
if(move_uploaded_file($_FILES['picture']['tmp_name'],$target))
{

	//Tells you if its all okay
	echo "The file" .basename($_FILES['uploadedfile']['name']). "has been uploaded, and your information has been added to the directory";
}
else{

	//Gives and error if its not
	echo "Sorry, there was a problem uploading your file.";
}
?>	

Like this?

$query = "INSERT INTO for_sale (position,year,make,model,price,description,picture)
                      VALUES ('$position','$year','$make','$model','$price','$description','$picture')
          ON DUPLICATE KEY UPDATE SET
                      year='$year', make='$make', model='$model',
                      price='$price', description='$description', picture='$picture'";
mysql_query($query) || die(mysql_error());

 

 

 

 

Got same 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 'ON DUPLICATE KEY UPDATE SET year='2007',"

I changed the server to a MySQL 5.0 database. I still cannot get it to work. I get "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 'SET year='2006', make='Mercedes', model='"

 

Any ideas?

 

<?php

//This is the directory where the images will be saved
$target="images/";
$target=$target.basename($_FILES['picture']['name']);

//This gets all the other information from the form
$position=$_POST['position'];
$year=$_POST['year'];
$make=$_POST['make'];
$model=$_POST['model'];
$price=$_POST['price'];
$description=$_POST['description'];
$picture=($_FILES['picture']['name']);

//Connects to Database
include "connect.php";

//Writes the information to the database
$query = "INSERT INTO forsale (position,year,make,model,price,description,picture)
                      VALUES ('$position','$year','$make','$model','$price','$description','$picture')
          ON DUPLICATE KEY UPDATE SET
                      year='$year', make='$make', model='$model',
                      price='$price', description='$description', picture='$picture'";
mysql_query($query) || die(mysql_error());

//Writes photo to the server
if(move_uploaded_file($_FILES['picture']['tmp_name'],$target))
{

	//Tells you if its all okay
	echo "The file" .basename($_FILES['uploadedfile']['name']). "has been uploaded, and your information has been added to the directory";
}
else{

	//Gives and error if its not
	echo "Sorry, there was a problem uploading your file.";
}
?>	

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.