Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
PHP-特定div上的打印输出错误_Php_Forms - Fatal编程技术网

PHP-特定div上的打印输出错误

PHP-特定div上的打印输出错误,php,forms,Php,Forms,我知道这个问题听起来很愚蠢,但我需要你的帮助。我的问题是我想在表单内部打印这个“错误”消息,而不是在表单外部打印。当前,“错误”消息打印在顶部 代码如下: 过程: if(!$name || !$email || !$comment){ //if not display an error message echo "<center>All fields are required</center>"; } else { mysql_select_db($data

我知道这个问题听起来很愚蠢,但我需要你的帮助。我的问题是我想在表单内部打印这个“错误”消息,而不是在表单外部打印。当前,“错误”消息打印在顶部

代码如下:

过程:

    if(!$name || !$email || !$comment){

//if not display an error message

echo "<center>All fields are required</center>";
}
else
{

mysql_select_db($database_connection, $connection);

$insert_query = sprintf("INSERT INTO contacts (name, email, comment, date, ip) VALUES (%s, %s, %s, NOW(), %s)",
                        sanitize($name, "text"),
                        sanitize($email, "text"),
                        sanitize($comment, "text"),
                        sanitize($ip, "text"));

$result = mysql_query($insert_query, $connection) or die(mysql_error());
}
if(!$name | |!$email | |!$comment){
//如果没有,则显示错误消息
echo“所有字段都是必需的”;
}
其他的
{
mysql\u select\u db($database\u connection,$connection);
$insert_query=sprintf(“插入联系人(姓名、电子邮件、评论、日期、ip)值(%s,%s,%s,NOW(),%s)”,
清理($name,“text”),
清理($email,“text”),
清理($comment,“text”),
消毒($ip,“文本”);
$result=mysql\u query($insert\u query,$connection)或die(mysql\u error());
}
表格:


  • 任何帮助都将不胜感激

    使用以下代码: 在PHP代码中:

    $nameError = "";
    $emailError = "";
    $commentError = "";
    if(!$name || !$email || !$comment){
    if(!$name){
      $nameError = "Name is required";  
    }
    if(!$email){
      $emailError = "Email is required";
    }
    if(!$comment) {
      $commentError = "Comment is required";
    }
    
    }
    else
    {
    
    mysql_select_db($database_connection, $connection);
    
    $insert_query = sprintf("INSERT INTO contacts (name, email, comment, date, ip) VALUES (%s, %s, %s, NOW(), %s)",
                            sanitize($name, "text"),
                            sanitize($email, "text"),
                            sanitize($comment, "text"),
                            sanitize($ip, "text"));
    
    $result = mysql_query($insert_query, $connection) or die(mysql_error());
    }
    
    在HTML代码中:

    <form id="contact" name="contact" action="index.php" method="post">
    
    <fieldset>
                   <li><input class="rounded" type="text" name="name" id="name" placeholder="Your Name" required />
                    </li>
                <span><?php echo ((isset($nameError) && $nameError != '') ? $nameError : ''); ?> </span> //do that with all the error where you want to place
                    <li>
                        <input class="rounded" type="text" name="email" id="email" placeholder="Your Email" required />
                    </li>
                    <li>
                        <textarea class="rounded" name="comment" id="comment" cols="35" rows="6" placeholder="Your Message" required ></textarea>
                    </li>
                    <input type="hidden" id="action" name="action" value="submitform" />
                    <li>
                    <input id="submit" name="submit" type="submit" value="Send" class="submitform" />
                    </li>
    </fieldset>
    </form>
    
    <form id="contact" name="contact" action="index.php" method="post">
    <?php if( isset($eror_msg) && $eror_msg != '' ) { echo $eror_msg; } ?>
    <fieldset>
    ----------------------------
    -------------------------------
    
    
    
  • //把所有的错误都放在你想放的地方
  • 使用以下代码: 在PHP代码中:

    $nameError = "";
    $emailError = "";
    $commentError = "";
    if(!$name || !$email || !$comment){
    if(!$name){
      $nameError = "Name is required";  
    }
    if(!$email){
      $emailError = "Email is required";
    }
    if(!$comment) {
      $commentError = "Comment is required";
    }
    
    }
    else
    {
    
    mysql_select_db($database_connection, $connection);
    
    $insert_query = sprintf("INSERT INTO contacts (name, email, comment, date, ip) VALUES (%s, %s, %s, NOW(), %s)",
                            sanitize($name, "text"),
                            sanitize($email, "text"),
                            sanitize($comment, "text"),
                            sanitize($ip, "text"));
    
    $result = mysql_query($insert_query, $connection) or die(mysql_error());
    }
    
    在HTML代码中:

    <form id="contact" name="contact" action="index.php" method="post">
    
    <fieldset>
                   <li><input class="rounded" type="text" name="name" id="name" placeholder="Your Name" required />
                    </li>
                <span><?php echo ((isset($nameError) && $nameError != '') ? $nameError : ''); ?> </span> //do that with all the error where you want to place
                    <li>
                        <input class="rounded" type="text" name="email" id="email" placeholder="Your Email" required />
                    </li>
                    <li>
                        <textarea class="rounded" name="comment" id="comment" cols="35" rows="6" placeholder="Your Message" required ></textarea>
                    </li>
                    <input type="hidden" id="action" name="action" value="submitform" />
                    <li>
                    <input id="submit" name="submit" type="submit" value="Send" class="submitform" />
                    </li>
    </fieldset>
    </form>
    
    <form id="contact" name="contact" action="index.php" method="post">
    <?php if( isset($eror_msg) && $eror_msg != '' ) { echo $eror_msg; } ?>
    <fieldset>
    ----------------------------
    -------------------------------
    
    
    
  • //把所有的错误都放在你想放的地方
  • 在PHP代码中:

    if(!$name || !$email || !$comment){
    //if not display an error message
        $eror_msg =  "<center>All fields are required</center>";
    }
    
    if(!$name | |!$email | |!$comment){
    //如果没有,则显示错误消息
    $eror\u msg=“所有字段均为必填项”;
    }
    
    在HTML代码中:

    <form id="contact" name="contact" action="index.php" method="post">
    
    <fieldset>
                   <li><input class="rounded" type="text" name="name" id="name" placeholder="Your Name" required />
                    </li>
                <span><?php echo ((isset($nameError) && $nameError != '') ? $nameError : ''); ?> </span> //do that with all the error where you want to place
                    <li>
                        <input class="rounded" type="text" name="email" id="email" placeholder="Your Email" required />
                    </li>
                    <li>
                        <textarea class="rounded" name="comment" id="comment" cols="35" rows="6" placeholder="Your Message" required ></textarea>
                    </li>
                    <input type="hidden" id="action" name="action" value="submitform" />
                    <li>
                    <input id="submit" name="submit" type="submit" value="Send" class="submitform" />
                    </li>
    </fieldset>
    </form>
    
    <form id="contact" name="contact" action="index.php" method="post">
    <?php if( isset($eror_msg) && $eror_msg != '' ) { echo $eror_msg; } ?>
    <fieldset>
    ----------------------------
    -------------------------------
    
    
    ----------------------------
    -------------------------------
    
    在PHP代码中:

    if(!$name || !$email || !$comment){
    //if not display an error message
        $eror_msg =  "<center>All fields are required</center>";
    }
    
    if(!$name | |!$email | |!$comment){
    //如果没有,则显示错误消息
    $eror\u msg=“所有字段均为必填项”;
    }
    
    在HTML代码中:

    <form id="contact" name="contact" action="index.php" method="post">
    
    <fieldset>
                   <li><input class="rounded" type="text" name="name" id="name" placeholder="Your Name" required />
                    </li>
                <span><?php echo ((isset($nameError) && $nameError != '') ? $nameError : ''); ?> </span> //do that with all the error where you want to place
                    <li>
                        <input class="rounded" type="text" name="email" id="email" placeholder="Your Email" required />
                    </li>
                    <li>
                        <textarea class="rounded" name="comment" id="comment" cols="35" rows="6" placeholder="Your Message" required ></textarea>
                    </li>
                    <input type="hidden" id="action" name="action" value="submitform" />
                    <li>
                    <input id="submit" name="submit" type="submit" value="Send" class="submitform" />
                    </li>
    </fieldset>
    </form>
    
    <form id="contact" name="contact" action="index.php" method="post">
    <?php if( isset($eror_msg) && $eror_msg != '' ) { echo $eror_msg; } ?>
    <fieldset>
    ----------------------------
    -------------------------------
    
    
    ----------------------------
    -------------------------------
    
    在要打印错误消息的位置添加以下代码:

    <div id="error_msg">  
        echo $error_msg;
    </div>
    
    
    echo$error\u msg;
    
    在要打印错误消息的位置添加以下代码:

    <div id="error_msg">  
        echo $error_msg;
    </div>
    
    
    echo$error\u msg;
    
    我在您的HTML1中没有看到任何错误消息占位符正如您所知,
    标记已被弃用。您的意思是我要在何处显示错误?如果是:所有字段都是必填的

    类似的内容?注意@HttpNinja:)知道如何在其中打印错误吗?我在HTML1中没有看到任何错误消息占位符正如您所知,
    标记已被弃用。您的意思是我要在何处显示错误?如果是:所有字段都是必填的

    类似的内容?注意@HttpNinja:)知道如何在其中打印错误吗?这正是我想要的。谢谢@Goutam Pal!这正是我想要的。谢谢@Goutam Pal!谢谢@Breaked Heart,这好多了!:)谢谢@Breaked Heart,这好多了!:)