How to use Insert or Update query in MYSQL
The INSERT OR UPDATE command is an extension of the INSERT command:
- If the row being inserted does not exist, INSERT OR UPDATE performs an INSERT operation.
- If the row being inserted already exists, INSERT OR UPDATE performs an UPDATE operation, updating the row with the specified column values. An update occurs even when the specified data values are identical to the existing data.
$cart = $this->common->select_raw_sql("INSERT INTO cart (user_id,product_id,quantity) VALUES ('".$_POST['user_id']."','" . $_POST["product_id"]. "','" . $_POST['quantity'] . "') ON DUPLICATE KEY UPDATE user_id='".$_POST['user_id']."', product_id='" . $_POST["product_id"]. "',quantity='" . $_POST['quantity'] . "',is_exists='".$is_exists."'",'row');
Tagged: