【问题标题】:database query redirecting to home directory数据库查询重定向到主目录
【发布时间】:2012-06-29 02:13:35
【问题描述】:

我有一个最简单的数据库条目,当我点击“提交”时,它会将我带到我的主目录,并且没有任何内容添加到数据库中。如何修复它以便输入数据?我过去使用相同的代码没有遇到过这样的问题...

<?php
 if(isset($_POST['submit'])) {
   $text = $_POST['text'];
   $link = mysql_connect("localhost", "******", "********") or die("Couldn't make connection.");
   @mysql_select_db("*****") or die("Couldn't select database");
   mysql_query("INSERT INTO wall (message) VALUES ('$text')");
 }
?>

<html>
 <form action="post" name="post" id="post">
  <input type="text" id="text" name="text"/>
  <input type="submit" name="submit" id="submit" value="submit"/>
 </form>
</html>

我知道我的密码和数据库名是正确的,因为当我拿走“form”和“isset”时,每次重新加载页面时上传都没有问题:

<?php
  $link = mysql_connect("localhost", "******", "*******") or die("Couldn't make connection.");
  @mysql_select_db("********") or die("Couldn't select database");
  mysql_query("INSERT INTO wall (message) VALUES ('test')");
?>

【问题讨论】:

    标签: php mysql redirect


    【解决方案1】:

    改变

    <form action="post" name="post" id="post">
    

    <form method="post" name="post" id="post">
    

    Action 是您希望表单提交到的页面 方法是类型(默认为get)

    【讨论】:

      【解决方案2】:

      你的表单没有方法,试试这个:

      <form method="post" name="post" id="post">
      
      </form>
      

      【讨论】:

        猜你喜欢
        • 2015-11-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多