[wd_asp elements=’search’ ratio=’100%’ id=1]

Mysqli Basic – ON DUPLICATE KEY UPDATE

30th August 2016

MySql

mysql codehaven category

The column called ‘ref’ will need to be unique. If it has a dupe, then it will complete the second part of the statement.

$results = $mysqli->query("INSERT INTO client_login (fname, sname, ref)
VALUES ('Mike', 'Belmond','T99')
ON DUPLICATE KEY UPDATE fname='Mike', sname='Belmond',ref='T100'");

if($results){
print 'Success! record updated / deleted';
}else{
print 'Error : ('. $mysqli->errno .') '. $mysqli->error;
}