Ok so I am having trouble getting the PHP for my registration form to work after I moved the forum to a JQuery Modal. Test 1 echos but Test 2 won't. Can anyone help? This is the header file for every page in my website. When this code is used on a regular page and not in modals it works. The php connection is initialized in the index.php file.
<?php
echo "test 1<br>";
$reg = $_POST['reg'];
$fn = "";
$ln = "";
$em = "";
$em2 = "";
$pswrd = "";
$pswrd2 = "";
$d = "";
$u_check = "";
$fn = strip_tags(@$_POST['fname']);
$ln = strip_tags(@$_POST['lname']);
$em = strip_tags(@$_POST['email']);
$em2 = strip_tags(@$_POST['email2']);
$pswrd = strip_tags(@$_POST['pw']);
$pswrd2 = strip_tags(@$_POST['pw2']);
$d = date("Y-m-d");
$u_check = mysql_query("SELECT email FROM users WHERE email='$em'");
$check = mysql_num_rows($u_check);
if(isset($_POST['reg'])){
echo " test 2";
if($fn&&$ln){
if($em == $em2){
if($pswrd == $pswrd2){
if($check == 0){
$pswrd = md5($pswrd);
$pswrd2 = md5($pswrd2);
$query = mysql_query("INSERT INTO users VALUES('', '$fn', '$ln', '$em', '$pswrd', '$d', '0')");
die("<h1>Registrastion Successful</h1>");
} }
else echo "<p id = 'regerror'>Email is already registered by a different user.</p>";
}
else echo "<p id = 'regerror'>Passwords do not match.</p>";
}
else echo "<p id = 'regerror'>Emails do not match.</p>";
}
else echo "<p id = 'regerror'>Please fill out all fields.</p>";
}
?>
<header id="header">
<div id="top-bar">
<div class="container">
<div class="row">
<div class="col-sm-12">
<ul id="top-info">
<li>Phone: </li>
<li>Email: </li>
</ul>
<ul id="top-buttons">
<?php
if($_SESSION['user_email'] == ""){
echo "<li><a href='#login' data-toggle='modal'><i class='fa fa-sign-in'></i> Login</a></li>
<li class='divider'></li>
<li><a href='#register' data-toggle='modal'><i class='fa fa-pencil-square-o'></i> Register</a></li>";
}
else{
echo "<li>Welcome, <a href='#'>".$_SESSION['user_fname']." ".$_SESSION['user_lname']."</a> - <a href = 'http://urbanares.com/logout/index.php'>log out</a></li>";
}?>
</ul>
</div>
</div>
</div>
</div>
<div class="sticky-wrapper"><div id="nav-section" class="">
<div class="container">
<div class="row">
<div class="col-sm-12">
<a href="http://urbanares.com/landing/index.php" class="nav-logo"><img src="../list_property/list_property_files/logo_transparent.png" alt="UrbanaRE Logo"></a>
<!-- BEGIN MAIN MENU -->
<nav class="navbar">
<button id="nav-mobile-btn"><i class="fa fa-bars"></i></button>
<ul class="nav navbar-nav">
<li><a href="http://urbanares.com/property_info/index.php?id=59">Buy</a></li>
<li><a href="http://urbanares.com/list_property">Sell</a></li>
<li><a href="">Rent</a></li>
<li><a href="">Videos</a></li>
<li><a href="">Seminars</a></li>
<!--<li><a href="">FAQ</a></li>
<li><a href="">About Us</a></li>
<li><a href="">Contact</a></li>-->
</ul>
</nav>
<!-- END MAIN MENU -->
</div>
</div>
</div>
</div>
</div>
<!--LOGIN MODAL -->
<div class="modal fade col-sm-4 col-sm-offset-4" id="login" role="dialogue">
<div class="modal-dialogue">
<div class="modal-content">
<div class="modal-header">
<h4>Login</h4>
</div>
<div class="modal-body">
<form action="#" method="">
<div class="form-group">
<div class="col-sm-12">
<input type="text" class="form-control" name="user_name" placeholder="email address">
</div>
<div class="col-sm-12">
<input type="text" class="form-control" type="password" name="user_password" placeholder="password">
</div>
<!-- END ADDRESS FORM -->
</div>
</form>
</div>
<div class="modal-footer">
<a class = "btn btn-warning" data-dismiss = "modal">Login</a><a class = "btn btn-warning" data-dismiss = "modal">Cancel</a>
</div>
</div>
</div>
</div>
<!--REGISTER MODAL -->
<div class="modal fade col-sm-4 col-sm-offset-4" id="register" role="dialogue">
<div class="modal-dialogue">
<div class="modal-content">
<form action="" method="POST">
<div class="modal-header">
<h4>Register</h4>
</div>
<div class="modal-body row">
<div class="form-group">
<div class="col-sm-12">
<input type="text" class="form-control" name="fname" placeholder="First Name">
</div>
<div class="col-sm-12">
<input type="text" class="form-control" name="lname" placeholder="Last Name">
</div>
<div class="col-sm-12"><br></div>
<div class="col-sm-12">
<input type="text" class="form-control" name="email" placeholder="Email Address">
</div>
<div class="col-sm-12">
<input type="text" class="form-control" name="email2" placeholder="Confirm Email Address">
</div>
<div class="col-sm-12">
<input type="text" class="form-control" name="pw" placeholder="Password">
</div>
<div class="col-sm-12">
<input type="text" class="form-control" name="pw2" placeholder="Re-type Password">
</div>
<!-- END ADDRESS FORM -->
</div>
</div>
<div class="modal-footer">
<a href="#" class = "btn btn-warning" name="reg">Sign Up</button><a class = "btn btn-warning" data-dismiss = "modal">Cancel</a>
</div>
</form>
</div>
</div>
</div>
</header>
答案 0 :(得分:1)
使用方法“POST”的表单时。确保使用带有type =“submit”的按钮来发送数据。 不要使用超链接
更改此代码:
<a href="#" class = "btn btn-warning" name="reg">Sign Up</button>
到:
<button type="submit" class = "btn btn-warning" name="reg" value="reg">Sign Up</button>