no dups

Codes here !

Moderators: macek, egami, gesf

New php-forum User
New php-forum User
Posts: 3
Joined: Sun Aug 12, 2012 2:56 pm

no dups

Postby dustty » Wed Aug 15, 2012 12:23 pm

I get a server error with this (I think syntax) but what is the proper syntax for ON DUPLICATE not to insert with dup sim_name?

What would it be if i wanted to insert into same row and update the other parameters for the same sim_name?

Code: Select all

$name = $_POST["sim"];
$simx = $_POST["xr"];
$simy = $_POST["yr"];
$simz = $_POST["zr"];
echo "$name";
$dbc = mysqli_connect("localhost" , "whitebu4_admin" , "admin1234" , "whitebu4_pads")
or die(mysqli_error());     
    mysql_query("INSERT INTO sims(sim_name,simx,simy,simz)
VALUES ('$name' , '$simx' ,'$simy','$simz') ON DUPLICATE KEY UPDATE sim_name=sim_name")
or die ('not inserted'  . mysql_error());  echo "$name,$simx has been inserted";

php-forum Fan User
php-forum Fan User
Posts: 578
Joined: Fri Aug 05, 2011 9:53 am

Re: no dups

Postby NigelRen » Fri Aug 17, 2012 12:32 am

I've seen things like

Code: Select all

INSERT INTO moviedb.genre (GenreID,GenreName)
VALUES ('18', 'Drama'),
    ('16', 'Animation')
  GenreName = VALUES(GenreName);

Try using the values() part where you want to set the value of the updated field.
Also as sim_name is probably your primary key - you don't need that in your update part.

Return to “mySQL & php coding”

Who is online

Users browsing this forum: No registered users and 1 guest