How to stop this MySQL from making new rows and update existing ones in wordpress (if exist update)

This code below takes custom field values an inserts it into another database everything works as it should except that it keeps creating new rows instead of updating them.

$sql = “INSERT INTO users (username, password, status, name, level, install_ver, apk_count, build_count, support_enabled, adb_version, device_count, rom_count)
VALUES (‘”.esc_attr( get_the_author_meta( ‘fw_name’, $user->ID ) ).”‘, ‘”.esc_attr( get_the_author_meta( ‘license_key’, $user->ID ) ).”‘, ‘”.esc_attr( get_the_author_meta( ‘fw_status’, $user->ID ) ).”‘, ‘”.esc_attr( get_the_author_meta( ‘fw_name’, $user->ID ) ).”‘, ‘”.esc_attr( get_the_author_meta( ‘fw_level’, $user->ID ) ).”‘, ‘”.esc_attr( get_the_author_meta( ‘fw_install’, $user->ID ) ).”‘, ‘”.esc_attr( get_the_author_meta( ‘fw_apk’, $user->ID ) ).”‘, ‘”.esc_attr( get_the_author_meta( ‘fw_build’, $user->ID ) ).”‘, ‘”.esc_attr( get_the_author_meta( ‘fw_support’, $user->ID ) ).”‘, ‘”.esc_attr( get_the_author_meta( ‘fw_adb’, $user->ID ) ).”‘, ‘”.esc_attr( get_the_author_meta( ‘fw_rom’, $user->ID ) ).”‘, ‘”.esc_attr( get_the_author_meta( ‘fw_devices’, $user->ID ) ).”‘)
ON DUPLICATE KEY UPDATE “;

if (mysqli_query($conn, $sql)) {
echo “New record created successfully”;
} else {
echo “Error: ” . $sql . “<br>” . mysqli_error($conn);
}
mysqli_close($conn);

Read more here:: How to stop this MySQL from making new rows and update existing ones in wordpress (if exist update)

Leave a Reply

Your email address will not be published. Required fields are marked *