php - Prepared statement with and without "on duplicate key update" -
i trying remove on duplicate key update because have duplicates. statement work , inserts data not duplicates. please help.
$sql = "insert projectselect (id_proj, project, role, id_agent) values ( ?,?,?, ( select idagency agentsinfo email = ?)) on duplicate key update `id_agent` = values(`id_agent`), `project` = values(`project`), `role` = values(`role`) "; if (($stmt = $con->prepare($sql)) === false) { trigger_error($con->error, e_user_error); } $result2= mysqli_query($con, $idq); $row_number = 1; while ($row = mysqli_fetch_array($result2)) { $id_proj= $row["id_proj"]; $project= $row["project"]; $role= $row["role"]; $id_proj++; } if ($stmt->bind_param("ssss", $id_proj, $postproj, $postrole, $_session["email"]) === false) { trigger_error($stmt->error, e_user_error); } if (($stmt->execute()) === false) { trigger_error($stmt->error, e_user_error); }
you have understand on duplicate key
triggered when insertion of record conflicts existing ones, , conflict happen when table has "unique" fields -- fields value can exist once among records of table.
first thing have fix remove unique
, primary
keys , indexes table. once done, whole thing should work already.
you can remove on duplicate key...
statement query once no longer relevant, keep code clean.
Comments
Post a Comment