0
我試圖使用相同的腳本批准的聯繫人添加到數據庫中,但查詢會做一個更新,如果主鍵(id )已經在那裏。所以,我成立了一個INSERT INTO ....對重複密鑰更新查詢,這是下面:
$resultsc = mysql_query("INSERT INTO $contact (id,First,Last,Companyid,userid,Title,PrimaryPhone,SecondaryPhone,PrimaryEmail,SecondayEmail,inserted) VALUES('$id','$first','$last','$companyid','$userid','$title','$phone1','$phone2','$email1','$email2',NOW()) ON DUPLICATE KEY UPDATE (First,Last,Companyid,userid,Title,PrimaryPhone,SecondaryPhone,PrimaryEmail,SecondayEmail) VALUES ('$first','$last','$companyid','$userid','$title','$phone1','$phone2','$email1','$email2') WHERE id='$id'");
if(!$resultsc)
{
echo "<font face='Verdana' size='2' ><center>You have successfully approved this user for access to this site.</center><br><center><input type='button' value='Back' onClick='history.go(-2)'></center>"; die();
}
else
{
echo "<font face='Verdana' size='2' ><center>You have not updated this contact for this site.</center><br><center><input type='button' value='Back' onClick='history.go(-2)'></center>";
}
我沒有得到任何錯誤,但數據庫沒有更新或插入新記錄。所以我檢查了我的「$ contacts」變量,以確保它指向正確的表,並且是。如果我只做一個插入,那麼腳本工作正常。但是,當我做這個查詢沒有任何反應。我想知道它有什麼問題,或者我應該只是有一個if/else與選擇檢查現有的密鑰?