doucuo9126 2017-05-04 21:32
浏览 12
已采纳

$ _POST崩溃网站

I have the below php page, which is a holding page with a contact form:

    <!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="author" content="">

    <!--<link rel="icon" href="../../favicon.ico">-->


    <title>Coming Soon</title>

    <!-- Bootstrap -->
    <link href="assets/css/bootstrap.css" rel="stylesheet">
    <link href="assets/css/bootstrap-theme.css" rel="stylesheet">
    <link href="assets/css/font-awesome.css" rel="stylesheet">

    <!-- siimple style -->
    <link href="assets/css/style.css" rel="stylesheet">

  </head>

  <body>

    <div id="wrapper">
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <h1>TEST</h1>
                    <h2 class="subtitle">We're working hard to improve our website and we'll be ready to launch soon
                    <h2 class="subtitle">Feel free to contact us below with any enquiries</h2>

                    <p>

                    <?php
                        $name = $_POST["contactname"];
                    ?>

                    <form class="Contact" method="post" action="">

                        <label class="alignleft">Name</label>
                        <input type="text" name="contactname" id="contactname" placeholder="Enter Name">

                        <label class="alignleft">Email</label>
                        <input name="Email" placeholder="Email Address">

                        <label class="alignleft">Enquiry</label>
                        <textarea name="Enquiry" placeholder="Your enquiry"></textarea><br>

                        <input id="submit" name="submit" type="submit" value="Submit!" class="btn btn-theme">

                    </form>

                <div class="social">
                        <a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                         <a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                         <!--<a href="#"><i class="fa fa-google-plus" aria-hidden="true"></i></a>
                         <a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a>-->
                    </div>
                </div>

            </div>

        </div>
    </div>
    <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
    <script src="assets/js/bootstrap.min.js"></script>

</body>
</html>

Within the php section I am trying to read the values of the input boxes, however even with only

$_POST["contactname"]; 

the website returns a 500 Internal Server Error. If i remove that line and replace with a simple:

echo "Test";

Then the site works and displays "Test"

If there something I am missing with the assigning of the variable from the input box?

  • 写回答

4条回答 默认 最新

  • doulu3808 2017-05-04 22:06
    关注

    I would recommend using a second file to process the form instead of having it all on one page. Not only does it make your code look cleaner but I find it can also help with debugging. So it will look something like this:

    index.php:

    <!DOCTYPE html>
    <html lang="en">
      <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="">
        <meta name="keywords" content="">
        <meta name="author" content="">
    
        <!--<link rel="icon" href="../../favicon.ico">-->
    
    
        <title>Coming Soon</title>
    
        <!-- Bootstrap -->
        <link href="assets/css/bootstrap.css" rel="stylesheet">
        <link href="assets/css/bootstrap-theme.css" rel="stylesheet">
        <link href="assets/css/font-awesome.css" rel="stylesheet">
    
        <!-- siimple style -->
        <link href="assets/css/style.css" rel="stylesheet">
    
      </head>
    
      <body>
    
        <div id="wrapper">
            <div class="container">
                <div class="row">
                    <div class="col-md-12">
                        <h1>TEST</h1>
                        <h2 class="subtitle">We're working hard to improve our website and we'll be ready to launch soon
                        <h2 class="subtitle">Feel free to contact us below with any enquiries</h2>
    
                        <form class="Contact" method="post" action="form_process.php">
    
                            <label class="alignleft">Name</label>
                            <input type="text" name="contactname" id="contactname" placeholder="Enter Name">
    
                            <label class="alignleft">Email</label>
                            <input name="Email" placeholder="Email Address">
    
                            <label class="alignleft">Enquiry</label>
                            <textarea name="Enquiry" placeholder="Your enquiry"></textarea><br>
    
                            <input id="submit" name="submit" type="submit" value="Submit!" class="btn btn-theme">
    
                        </form>
    
                    <div class="social">
                            <a href="#"><i class="fa fa-facebook" aria-hidden="true"></i></a>
                             <a href="#"><i class="fa fa-twitter" aria-hidden="true"></i></a>
                             <!--<a href="#"><i class="fa fa-google-plus" aria-hidden="true"></i></a>
                             <a href="#"><i class="fa fa-linkedin" aria-hidden="true"></i></a>-->
                        </div>
                    </div>
    
                </div>
    
            </div>
        </div>
        <script src="https://code.jquery.com/jquery-1.10.2.min.js"></script>
        <script src="assets/js/bootstrap.min.js"></script>
    
    </body>
    </html>
    

    form_process.php:

    <?php
        if(isset($_POST['contactname'])
        {
            $name = $_POST['contactname'];
            if(empty($name))
            {
                die("contact name is empty")
            }
            else
            {
                echo $name;
            }   
        }
        // Continue processing form data
    ?>
    

    I would also follow the recommendations from other users about displaying PHP errors.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码