doushi1912 2015-05-21 18:14
浏览 10

PHP表单语法错误[重复]

This question already has an answer here:

again i trying to do a simple contact form for sending email,

thats the code:

<?php

if (empty($_POST) === false) {
   $errors = array();

   $name     = $_POST['name'];
   $email    = $_POST['email'];
   $message  = $_POST['message'];

   echo $name,' ', $email, ' ', $message;

   if (empty($name) === true || empty($email) === true || empty($message) === true) {
    $errors[] = 'name,email and message are required';

   } else{
     if(filter_var($email,FILTER_VALIDATE_EMAIL) === false){
        $errors[] = 'that\'s not a valid email address';

     }
      if(ctype_alpha($name) === false) {

        $errors ='name must only contain letters';
      }
}

if (empty($errors) ===true) {


    mail('talrod160@gmail.com','contact form','$message','From:' . $email);
    header('location:index.php?sent');
    exit();


}

?>

<!DOCTYPE html>
<html>
    <head>
        <title>A contact form</title>
    </head>
    <body>
    <?php
    if (isset($GET ['sent']) === true) {
     echo '<p>Thanks for contact us<?/p>';
   
    } else {


        if (empty($errors) === false) {
          echo '<ul>';
          foreach($errors as $error) {
            echo '<li>', $error, '</li>';
          }
           echo '</ul>';

        }

        ?>

        <form action="" method="post">
          <p>
             <label for="name">Name:</label><br>
             <input type="text" name="name" id="name" <?php if (isset($_POST['name']) === true){echo ($_POST['name']), '"'} ?>>
         </p>

         <p>
             <label for="email">Email:</label><br>
             <input type="text" name="email" id="email"<?php if (isset($_POST['email']) === true){echo 'value="', ($_POST['email']), '"'} ?>>
        </p>


         <p>
             <label for="message">Message:</label><br>
             <textarea name="message" id="message"><?php if (isset($_POST['message']) === true) { echo strip_tags ($_POST['message']); } ?></textarea>
        </p>

        <p>
        <input type="submit" value="Submit">
       </p>
        </form>
        <?php
         }
        ?>        

    </body>

</html>

now i get this problem and cant understand why,

Parse error: syntax error, unexpected '<' in D:\xampp\htdocs\contact_form\index.php on line 46

and would like if someone can explain me me about foreach loop

thanks.

</div>
  • 写回答

1条回答 默认 最新

  • dongna1593 2015-05-21 18:23
    关注

    <p>Thanks for contact us<?/p> probably should be <p>Thanks for contact us</p>

    评论

报告相同问题?

悬赏问题

  • ¥15 求解 yolo算法问题
  • ¥15 虚拟机打包apk出现错误
  • ¥30 最小化遗憾贪心算法上界
  • ¥15 用visual studi code完成html页面
  • ¥15 聚类分析或者python进行数据分析
  • ¥15 三菱伺服电机按启动按钮有使能但不动作
  • ¥15 js,页面2返回页面1时定位进入的设备
  • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
  • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
  • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝