我想知道如何在提交表单后显示“所有必填字段”通知但之前将其隐藏。这是我的代码:
if (isset($_POST['region'], $_POST['description'], $_POST['remarks']) && !empty ($_POST['region']) && !empty($_POST['description']) && !empty($_POST['remarks']) )
{
$region = mysql_escape_string($_POST['region']);
$description = mysql_escape_string($_POST['description']);
$remarks = mysql_escape_string($_POST['remarks']);
if (strlen($region>50)) {
$error .= "Only 50 characters are allowed in the region field.";
}
else {
if (strlen($description>500)) {
$error .= "Only 500 characters are allowed in the region field.";
}
else {
mysql_query("INSERT INTO register (region, description, remarks) VALUES(
'$region',
'$description',
'$remarks') ") or die('Not saved. ' . mysql_error());
}
}
}
else {
$error.= "Please fill all the fields.";
}
echo $error;
?>
//form starts here
但是,即使是第一次加载页面(不提交输入),使用它也会显示“请填写所有字段”。我该怎么做?另外,即使是嵌套的 'if' 也不起作用。这些字符串仍然可以提交:(