0

我尝试使用 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(); }


?>
4

2 回答 2

2

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

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

如果您不指定表单操作,它将在提交时将请求发送到相同的 URL,例如您正在谈论的“刷新”。

于 2013-09-04T14:54:38.797 回答
1

看起来您在表单操作 URL 中有错字。

php_icludes/sign_php.php

我猜应该是:

php_includes/sign_php.php
于 2013-09-04T15:42:54.330 回答