douying9296 2017-05-26 23:15
浏览 70
已采纳

PHP $ _GET和$ _POST代码不起作用

I have some PHP code and when executed the code doesn't send the values to the other PHP page on my site. My permissions are 755.

Page 1:

       <!DOCTYPE html>
<html lang="en">
<head>
  <title>Bay Area Buckets</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
  <style>

  .navbar {
    margin-bottom: 0;
    background-color: #ff4d4d;
    z-index: 9999;
    border: 0;
    font-size: 12px !important;
    line-height: 1.42857143 !important;
    letter-spacing: 4px;
    border-radius: 0;
}

.navbar li a, .navbar .navbar-brand {
    color: #fff !important;
}

.navbar-nav li a:hover, .navbar-nav li.active a {
    color: #f4511e !important;
    background-color: #fff !important;
}

.navbar-default .navbar-toggle {
    border-color: transparent;
    color: #fff !important;
}
.resize {
   border: 2px solid;
    padding: 20px; 

    resize: vertical;
    overflow: auto;


}
textarea {
    width: 100%;
}

  </style>
</head>
<body>

 <nav class="navbar navbar-default navbar-fixed-top">
  <div class="container">
    <div class="navbar-header">
      <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#myNavbar">
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
        <span class="icon-bar"></span>
      </button>
     <a href="index"><img src="https://pbs.twimg.com/media/CnvlpmKUAAArtx_.png:large" alt="Logo" height="60" width="60"></a> 
    </div>
    <div class="collapse navbar-collapse" id="myNavbar">
      <ul class="nav navbar-nav navbar-right">

     <li><a href="index">HOME</a></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>
        <li><a href="about">ABOUT</a></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>
        <li><a href="hats">HATS</a></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>
        <li><a href="socialMedia">SOCIAL MEDIA</a></li><li>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</li>
        <li><a href="cart">Cart</a></li>

      </ul>
    </div>
  </div>
</nav>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
<br/>
    <div>
        <center><h1 ><span style="color:#ff6666;">Contact Us</span></h1></center>
    </div>
<br/>
<br/>
<br/>
<?php
echo '<div class="col-md-3"></div>
<div class="col-md-6">
    <form action="contact.php" method="post">
    Name:
    <br>
    <input type="text" name="name"/ >
    Email: 
    <br>
    <input type="text" name="email"/>
    Message:
    <br>
    <textarea class="riseize" value="text" name="message"></textarea>
    <br>
    <center><input type="submit" value="submit"/></center>
    </form>
</div>
</div>
<div class="col-md-3"></div>'
?>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
</div>
</body>
</html>

Calls contact.php which is:

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

$sql = "INSERT INTO help (name, email, message) VALUES ( '$name' , '$email' , '$message' )";

if (!mysql_query($sql)) {
die ('Error: ' . mysql_error());
}
else {
echo "<html><script language='JavaScript'> alert('Thank you for your submission.'),window.location = 'index'</script></html>";
};

I think the problem is the get $_GET and $_POST because it executes contact.php and calls the variable values, but it doesn't get the values from the page 1.

  • 写回答

3条回答 默认 最新

  • dongye6377 2017-05-27 04:01
    关注

    You close the form when you open it. Change:

    <form action="contact.php" method="post" />
    

    to:

    <form action="contact.php" method="post">
    

    the / closes the element, basically you have

    <form action="contact.php" method="post"></form>
    

    then all your other inputs go to nothing.

    (Other issues mentioned also are true, but this is why your form is empty)

    In your browser you also should use the developer console (location and options vary by browser) to see how the request is sent and processed. https://wpscholar.com/blog/view-form-data-in-chrome/ This will show you first if it is an issue with the form sending, or the PHP processing it (e.g. if the values aren't sent you know it is not a PHP issue).

    As it turned out in this case you had a rewrite in place that stripped the .php, also removing parameters. Making a direct request to the page, bypassing the rewrite rule resolved this.

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

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP