我有一个问题,不是检查是否有重复,而是下面的脚本只是将行插入到 mysql 中,根本没有更新。我一次又一次地尝试,但总是有重复。
我在这里到底做错了什么?
if ($completeStatus == "0") {
// Get the default questions responses and insert into database
$questionsAnswered = $_GET['questions'];
foreach( $questionsAnswered as $key => $answers){
$query = "INSERT INTO survey_ResponseDetail (responseHeader,
questionID,
questionText,
ansLikelihood,
ansExpConsq,
ansRepRisk,
currWayMitigate
)
VALUES ('$ResponseHeader',
'$key',
'test1',
'$answers[1]',
'$answers[2]',
'$answers[3]',
'$answers[4]'
)
ON DUPLICATE KEY UPDATE ansLikelihood = '$answers[1]',
ansExpConsq = '$answers[2]',
ansRepRisk = '$answers[3]',
currWayMitigate = '$answers[4]',
id = LAST_INSERT_ID(id)";
$dbresult = mysql_query($query) or die ('Database Error (' . mysql_errno() . ') ' . mysql_error());
}