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