Codes here !
Moderators: macek, egami, gesf
by 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
<?php
$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";
}
}
msqli_close($dbc);
?>
-
dustty
- New php-forum User

-
- Posts: 3
- Joined: Sun Aug 12, 2012 2:56 pm
by 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')
ON DUPLICATE KEY UPDATE
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.
-
NigelRen
- php-forum Active User

-
- Posts: 450
- Joined: Fri Aug 05, 2011 9:53 am
Return to mySQL & php coding
Who is online
Users browsing this forum: No registered users and 1 guest