Bootstrap在提交时刷新页面

时间:2013-09-04 14:28:39

标签: php sql forms twitter-bootstrap

我尝试使用Bootstrap创建一个注册表单并且我一直遇到这些问题:单击“提交”按钮后页面刷新,它将不会打开PHP文件并将用户名插入数据库。

以下是代码:

<?php

?>


<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title>Memory Line - Sign Up Page</title>

        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <link rel="stylesheet" href="../bootstrap/css/bootstrap.css">
        <link rel="stylesheet" href="../bootstrap/css/bootstrap-responsive.css">
    </head>
    <body>
        <script src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
        <script src="../bootstrap/js/bootstrap.js"></script>
        <script src="js/sign_up_js.js"></script>
        <script src="js/main.js"></script>
        <script src="js/ajax.js"></script>




        <div class="navbar navbar-fixed-top">
            <div class="navbar-inner">
                <div class="container">
                    <a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
                        <span class="icon-th-list"></span>
                    </a>
                    <a href="#" class="brand">Memory Line</a>
                    <div class="nav-collapse collapse">
                        <ul class="nav pull-right" >
                            <li class="active"><a href="#">Home</a></li>
                            <li class="divider-vertical"></li>
                            <li><a href="#">About Us</a></li>
                            <li class="divider-vertical"></li>
                            <li><a href="#">Contact</a></li>
                        </ul>
                    </div>
                </div>
            </div>
        </div> <!--top navbar-->



        <div class="row-fluid">
            <div class="span4">
                <div class="well well-large">
                    <form>
                        <fieldset>
                            <h2>Login!</h2>
                            <input type="text" class="input-block-level" placeholder="Username"> <!--username-->
                            <input type="text" class="input-block-level" placeholder="Password"> <!--password-->
                            <button id="sumbit_btn" class="btn btn-primary" type="submit"  >Sumbit</button> <!--login btn-->
                        </fieldset>
                    </form>
                </div>
            </div> <!--login form-->


            <div class="span8">
                <div class="well well-large">
                    <h2>Sign Up!</h2>
                    <form>
                        <fieldset> 
                            <form method="post" action="php_icludes/sign_php.php" >


                                    <input type="text" class="input-block-level" placeholder="Username" name="username" maxlength="16">

                                    <input type="submit" value="submit" />

                            </form>
                        </fieldset>
                    </form>
                </div>
            </div>
        </div>



    </body>
</html>

这是将数据插入数据库的PHP文件:

    <?php
include_once("db_conx.php");

/* Now, we select the database */
mysql_select_db("Database Name");

$u = preg_replace('#[^a-z0-9]#i', '', $_POST['username']);

$sql = "INSERT INTO users (username) VALUES('$u')";
        $query = mysqli_query($db_conx, $sql); 

if($query)
{ echo "Registration Succesfull"; }
else
{ echo "error in registration".mysql_error(); }


?>

2 个答案:

答案 0 :(得分:2)

您是否忘记在表单标记中指定action属性?

<form action="/where-is-the-2nd-file.php" method="post">
   ...
</form>

如果您没有指定表单操作,它会在提交时向同一个URL发送请求,例如您正在谈论的“刷新”。

答案 1 :(得分:1)

您似乎在表单操作网址中输入了拼写错误。

php_icludes/sign_php.php

我猜应该是:

php_includes/sign_php.php