如何在php中回显查询生成的空条目禁止消息?

如何在php中回显查询生成的空条目禁止消息?,php,mysqli,Php,Mysqli,我有一个表单,在提交时检查此查询-> if(isset($_POST['update']) && !empty($_POST['name']) && !empty($_POST['reg_name'])) 我想回显一条消息“请填写所有必填字段”。如果必填字段未填写 简而言之,它应该突出显示未填充的字段名 完整代码: include ('database/abcd.php'); if ($con->connect_error) { die("Co

我有一个表单,在提交时检查此查询->

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();
}
include('database/abcd.php');
如果($con->connect\u错误)
{
die(“连接失败:”.$con->connect\U错误);
} 
如果(isset($_POST['update']))
{
$error=array();
if(空($_POST['name']))
$error[]=“请填写名称字段”;
if(空($\u POST['reg\u name']))
$error[]=“请填写注册表名字段”;
如果(计数($error)<1)
{
$name=$_POST['name'];
$reg\u name=$\u POST['reg\u name'];
$ESTABLED=$_POST['ESTABLED'];
$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\u username=$\u会话['username'];
$process=“在通知(成员\用户名、流程、图标、类)中插入值(“$\发布[成员\用户名]”、“$\发布[流程]、“$\发布[图标]、“$\发布[类]”)”;
if(!mysqli_query($con,$process))
{
die('Error:'.mysqli_Error($con));
}
$sql="更新`company\u meta`SET`name`='$name',reg\u name='$reg\u name',wiki='$wiki',builded='$builded',industry='$industry',about='$about',website='$website',mail='$mail',phone='$phone',address='$address',city='$city='$facebook='$facebook',twitter='$twitter',google其中`member'$google username`='$member_用户名';
如果($con->query($sql))
{
标题('Location:edit.php');
} 
}
其他的
{  
$errors=内爆(','$error);
回音$错误;
}
$con->close();
}
if(isset($\u POST['update'])//首先检查它是否是一个更新调用
{
$error=array();//这里我们初始化一个数组,以便将消息放入其中。
if(empty($\u POST['name'])//如果name字段为空,则在$error数组中推送消息。
$error[]=“请填写名称字段”;
if(空($\u POST['reg\u name'])//与上述字段相同
$error[]=“请填写注册表名字段”;
if(count($error)<1)//现在检查$error数组是否没有值。如果有值,则表示上面的一个或两个字段为空,并且将执行else块。
{
//提交你的表格
}
其他的
{
$errors=内爆(','$error);
回音$错误;
}
}
其他的
{
//更新未触发。
}

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

您是在开玩笑吧?实际上我对PHP非常陌生,所以不太了解。进行了一些研究,但没有结果。试试这个
echo“请填写所有必填字段。“;
但首先尝试一下这是你在谈论的->如果(设置($\u POST['update'])&!空($\u POST['name'])&&!空($\u POST['reg\u name'])){}否则{echo“请填写所有必填字段。”;}查看
$\u POST
@Raheel代码禁止空输入,但回显部分没有显示。我的意思是它应该回显未填充的字段。@RaheelKhan it only echos”数组“当提交空条目时,@M.Doye是我做的。如果你能取消否决票,那就太好了。Thanks@ArijitAich你把echo放在哪里了?
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.
}