我有一个注册表,如果“ID”不存在,我会尝试插入数据。它工作正常。如果“ID”已经存在,现在我正在尝试更新数据。它根本不起作用,我找不到错误。如果 ID 存在与否,这是我设置的条件:
function staff_detail_exist($ic) {
$result = null;
$sql = "SELECT * FROM apply WHERE staffid = '$ic'";
$data = mysql_query($sql);
if (mysql_num_rows($data) == 0) {
$result = "available";
} else {
$result = "exist";
}
return $result;
}
这是我的插入和更新功能:
if (staff_detail_exist($ic) == "available") {
insert_staff_detail($ic, $name, $contact, $mail, $address, $paytype, $applicant);
echo "Workshop application successful! You will be notified shortly via E-mail after confirmation! Thank You!";
}
else if (staff_detail_exist($ic) == "exist") {
update_staff_detail($ic, $name, $contact, $mail, $address, $paytype);
echo "Staff Details Updated!" ;
}
function insert_staff_detail($ic, $name, $contact, $mail, $address, $paytype, $applicant) {
$sql = "INSERT INTO apply (staffid, staffname, staffno, staffemail, staffaddress, paytype, applicant) VALUES ('$ic', '$name', '$contact', '$mail', '$address','$paytype', '$applicant')";
mysql_query($sql);
}
function update_staff_detail($ic, $name, $contact, $mail, $address, $paytype){
$sql = "UPDATE apply
SET staffname='$_POST[name]',
staffno='$_POST[contact]',
staffmail='$_POST[mail]',
address='$_POST[address]',
paytype='$_POST[paytype]'
WHERE staffid='$_POST[ic]'";
mysql_query($sql);
}
请问有什么建议吗?谢谢!