Reputation: 3
I've tried to create a signup form with Bootstrap and I keep having these problems: the page refreshes after I click the Submit button and it won't open the PHP file and insert the username into the database.
Here is the code:
<?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>
And here is the PHP file which inserts the data into the database:
<?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(); }
?>
Upvotes: 0
Views: 2129
Reputation: 1239
It looks like you have a typo in the form action URL.
php_icludes/sign_php.php
I'm guessing that should be:
php_includes/sign_php.php
Upvotes: 1
Reputation: 303
Did you forget to specify the action attribute in your form tag?
<form action="/where-is-the-2nd-file.php" method="post">
...
</form>
If you don't specify the form action, it will send request to the same URL when submitting, like "refresh" you're talking about.
Upvotes: 2