如何回显php中查询生成的Empty Entry Prohibited Message


How to echo Empty Entry Prohibited Message generated from a query in php?

我有一个表单,提交时会检查这个查询->

if(isset($_POST['update']) && !empty($_POST['name']) && !empty($_POST['reg_name']))

如果必填字段没有填写,我想回显一条消息"请填写所有必填字段"。

简而言之,它应该突出显示未填充的字段名称。

完整代码:

include ('database/abcd.php');
if ($con->connect_error) 
{
    die("Connection failed: " . $con->connect_error);
} 
if(isset($_POST['update']))
{
$error = array();
if(empty($_POST['name']))
    $error[] = 'Please fill name field';
if(empty($_POST['reg_name']))
    $error[] = 'Pleae fill reg_name field';
if(count($error) < 1)
{
    $name = $_POST['name'];
    $reg_name = $_POST['reg_name'];
    $established = $_POST['established'];
    $industry = $_POST['industry'];
    $about = $_POST['about'];
    $website = $_POST['website'];
    $mail =  $_POST['mail'];
    $phone = $_POST['phone'];
    $address =  $_POST['address'];
    $city = $_POST['city'];
    $facebook = $_POST['facebook'];
    $wiki = $_POST['wiki'];
    $twitter = $_POST['twitter'];
    $google = $_POST['google'];
    $member_username = $_SESSION['username'];
    $process="INSERT INTO notifications (member_username, process, icon, class) VALUES ('$_POST[member_username]','$_POST[process]','$_POST[icon]','$_POST[class]')";
    if (!mysqli_query($con,$process))
    {
      die('Error: ' . mysqli_error($con));
    }

    $sql = "UPDATE `company_meta` SET `name` = '$name', reg_name = '$reg_name', wiki = '$wiki', established = '$established', industry = '$industry', about = '$about', website = '$website', mail = '$mail', phone = '$phone', address = '$address', city = '$city', facebook = '$facebook', twitter = '$twitter', google = '$google' WHERE `member_username` = '$member_username'";
    if ($con->query($sql)) 
    {
        header('Location: edit.php');           
    } 
}
else
{  
    $errors = implode(',' $error); 
  echo $errors;   
}
    $con->close();
}

我认为您传入的name或reg_name是先检查的。可能是name或regname可以包含空白,这样它就不会显示消息,否则上面的代码工作正常。。

if(isset($_POST['update'])) // This first check whether it is an update call
{
   $error = array();  // Here we initialize an array so that we can put the messages in it.
   if(empty($_POST['name'])) // If the name field is empty, push a message in $error array.
    $error[] = 'Please fill name field';
   if(empty($_POST['reg_name'])) // Same as above field
    $error[] = 'Pleae fill reg_name field';
   if(count($error) < 1) // Now this checks if the $error array has no value. If it has value it means that either or both of the above fields are empty and the else block will be executed.
   {
      // Submit your form
   }
   else
   {
      $errors = implode(',' $error); 
      echo $errors;
   }
}
else
{
    // Update not triggered.
}