Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/272.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/amazon-s3/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php ';提交评论';重定向到另一页_Php_Html_Mysql_Database_Phpmyadmin - Fatal编程技术网

Php ';提交评论';重定向到另一页

Php ';提交评论';重定向到另一页,php,html,mysql,database,phpmyadmin,Php,Html,Mysql,Database,Phpmyadmin,我将在我的网站上建立一个评论区。我在评论框中发表了评论。发布评论并将其更新到数据库中效果良好。但问题是,在提交任何评论时,它会将我导航到第一页(在我的情况下,它是“主页”选项卡下的主页)。它不允许用户停留在同一页面上 main.php: <!--php code for comment section starts--> <?php mysql_connect("localhost","root",""); mysql_select_db("comment_

我将在我的网站上建立一个评论区。我在评论框中发表了评论。发布评论并将其更新到数据库中效果良好。但问题是,在提交任何评论时,它会将我导航到第一页(在我的情况下,它是“主页”选项卡下的主页)。它不允许用户停留在同一页面上

main.php:

<!--php code for comment section starts--> 

<?php
    mysql_connect("localhost","root","");
    mysql_select_db("comment_section");
    $name=isset($_POST['name'])? $_POST['name'] : '';
    $comment=isset($_POST['comment'])?$_POST['comment'] : '';
    $submit=isset($_POST['submit'])?$_POST['submit'] : '';

    $dbLink = mysql_connect("localhost","root","");
    mysql_query("SET character_set_client=utf8", $dbLink);
    mysql_query("SET character_set_connection=utf8", $dbLink);

    if($submit) {
        if($name&&$comment) {
            $insert=mysql_query("INSERT INTO comment (name,comment) VALUES ('$name','$comment') ");
        } else {
            echo "please fill out all fields";
        }
    }
?>

<!--php code for comment section ends--> 
<!--building a comment section starts-->

<center>
    <form action="" method="POST">
        <table>
            <tr><td>Name: <br><input type="text" name="name"/></td></tr>
            <tr><td colspan="2">Comment: </td></tr>
            <tr><td colspan="5"><textarea name="comment" rows="10" cols="50"></textarea></td></tr>
            <tr><td colspan="2"><input type="submit" name="submit" value="Comment"></td></tr>
        </table>
    </form>

<!--building a comment section ends-->
<!--building a comment section's functionality starts-->
<?php
    {
        $dbLink = mysql_connect("localhost","root","");
        mysql_query("SET character_set_results=utf8", $dbLink);
        mb_language('uni');
        mb_internal_encoding('UTF-8');

        $getquery=mysql_query("SELECT * FROM comment ORDER BY id DESC");
        while($rows=mysql_fetch_assoc($getquery)) {
            $id=$rows['id'];
            $name=$rows['name'];
            $comment=$rows['comment'];

            echo $name.'<br />'.'<br />'.$comment .'<br/>'.'<br/>'.'<hr size="1"/>';
        }    
    }    
?>
<!--building a comment section's functionality ends-->


尝试放置
而不是
。此外,您的代码容易受到SQL注入的攻击。请参阅以了解我的意思以及如何防止它。

此评论框位于主页或任何左、右面板上


如果是,请尝试将“文件路径”放入
评论框不在主页中,而是在另一个页面中。但是我在一个文件(main.php内部)中编写了所有代码。这就是我没有任何其他文件的原因;出口在插入查询后,你想在哪里重定向用户..PHP开发者,你能让我再澄清一下吗?你的意思是我应该添加一个头标签?PHP开发者,我试过了,它不应该工作。因为我没有为不同的选项卡创建任何单独的文件。所有页面都写在一个(main.php)文件中。我的评论框位于我的“关于我”页面中。插入评论后,它会将我重定向到我的主页。这可能是因为我的主页和关于我的页面都写在同一个文件下。在这里发布我的url在这里如何重定向到“关于我”页面。你使用散列链接了吗?意思是我试过的“关于我”页面的URL,它不应该工作。因为我没有为不同的选项卡创建任何单独的文件。所有页面都写在一个(main.php)文件中。我的评论框位于我的“关于我”页面中。插入评论后,它会将我重定向到我的主页。这可能是因为我的主页和关于我的页面都写在一个文件下。
if($submit)
{
  if($name!='' && $comment!='')
  {
   $insert=mysql_query("INSERT INTO comment (name,comment) VALUES ('$name','$comment') ");
   header("location:your filename.php");
   exit;
  }
}