dongwen7187 2018-03-05 04:20
浏览 43

PHP联系表单仍然无效

I know a number of people have tried to answer this question but I have to ask because I have tried all the proposed solutions and none of them work for me. Whenever I attempt to test the PHP code it displays the error 'Cannot POST /contact.php'.

    <!DOCTYPE html>
    <html lang="en">

    <head>
      <meta charset="UTF-8">
      <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
      <meta name="viewport" content="width=device-width,initial-scale=1,maximum-scale=1,user-scalable=no">
      <meta name="HandheldFriendly" content="true">
    </head>
    <body>
      <form action="contact.php" method="post">
        <div class="container-fluid contact-form">
          <div class="row centered content">
            <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 b1">
              <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 b1">
                <input class="contact-info name" type="text" placeholder="Name" name="yourname" />
              </div>
              <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 b1">
                <input class="contact-info email" type="text" placeholder="Email" name="email" />
              </div>
              <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 b1">
                <input class="contact-info number" type="text" placeholder="Contact number" name="comments" />
              </div>
              <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 b1">
                <input class="contact-info subject" type="text" placeholder="Subject" name="subject" />
              </div>
            </div>

            <div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-xl-6 b2">
              <textarea class="contact-message" name="comments" placeholder="Message" rows="10" cols="40"></textarea>


              <p class="how">How did you find out about 9haus?
                <select name="how">
    <option class="select" value=""> -- Please select -- </option>
    <option>Google search</option>
    <option>From a friend</option>
    <option>Link from a website</option>
    <option>9haus Publications</option>
    <option>Other</option>
    </select>
              </p>
            </div>
          </div>
          <div class="container-fluid contact-f">
            <div class="row centered">
              <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12 col-xl-12 b">
                <p><input class="send" type="submit" name="submit" value="Send"></p>
              </div>
            </div>
          </div>
        </div>
      </form>
    </div>
  </div>
 </body>
 </html>

And now the PHP code

<?php
/* Set e-mail recipient */
$myemail  = "review@studios.com";

/* Check all form inputs using check_input function */
$yourname = check_input($_POST['yourname'], "Enter your name");
$email    = check_input($_POST['email']);
$comments = check_input($_POST['comments'], "Write your comments");
$subject  = check_input($_POST['subject'], "Write a subject");
$how_find = check_input($_POST['how']);
$comments = check_input($_POST['comments'], "Write your comments");

/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
    show_error("Please enter valid email address");
}

/* If URL is not valid set $website to empty */
if (!preg_match("/^(https?:\/\/+[\w\-]+\.[\w\-]+)/i", $website))
{
    $website = '';
}

if(isset($_POST['submit'] && $human == '15')

else if(isset($_POST['submit'] && $human != '15')   

/* Let's prepare the message for the e-mail */
$message = "Hello!

Your request has been submitted to the 9haus graphics team:

Name: $yourname
E-mail: $email
URL: $website

How did he/she find it? $how_find

Comments:
$comments

End of message
";

/* Send the message using mail() function */
mail($myemail, $subject, $message);


/* Functions we used */
function check_input($data, $problem='')
{
    $data = trim($data);
    $data = stripslashes($data);
    $data = htmlspecialchars($data);
    if ($problem && strlen($data) == 0)
    {
        show_error($problem);
    }
    return $data;
}

function show_error($myError)
{
?>
    <html>
    <body>

    <b>Please correct the following error:</b><br />
    <?php echo $myError; ?>

    </body>
    </html>
<?php
exit();
}
?>

Any thoughts as to what I might be doing wrong?

  • 写回答

1条回答 默认 最新

  • drwjv28028 2018-03-05 08:17
    关注

    After just checking your PHP code "contact.php" file, seems like there is syntax error coming on your if/else conditional statements. i.e

    if(isset($_POST['submit'] && $human == '15')
    
    else if(isset($_POST['submit'] && $human != '15') 
    

    Try commenting these two statements, after then you will be able to POST to contact.php file.

    Note: Here my only intension is to help you finding the root cause. You will then need to fix these conditional statements.

    Hope it helps.

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)