有代码:
$id = $_POST['id'];
$name = $_POST['name'];
$surname = $_POST['surname'];
$mail = $_POST['mail'];
$sql = "UPDATE emps SET";
$moresql = '';
if(isset($name) && !empty($name)) {
$moresql .= " name = '$name'";
}
if(isset($surname) && !empty($surname)) {
if ($moresql) $moresql .= ',';
$moresql .= " surname = '$surname'";
}
if(isset($mail) && !empty($mail)) {
if ($moresql) $moresql .= ',';
$moresql .= " mail = '$mail'";
}
$sql .= $moresql;
$sql .= " WHERE Id = '$id'";
在此代码中,我可以更新例如:姓名并保留姓氏和电子邮件中的现有值或更新姓氏并留下姓名并通过电子邮件发送现有值
但我也想一次,例如:更新姓名和姓氏并留下电子邮件现有值或更新姓氏和电子邮件并留下姓名现有值或更新所有字段。如何?