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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料