我使用dreamweavers自动填充来获取php登录并注册东西,但是当我点击按钮时没有任何反应...我已经尝试将按钮放在表单内外,我已经看了很多教程,他们都做同样的事情的事情。
<?php require_once('../Connections/localhost.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
// *** Redirect if username exists
$MM_flag="MM_insert";
if (isset($_POST[$MM_flag])) {
$MM_dupKeyRedirect="index.php";
$loginUsername = $_POST['Username'];
$LoginRS__query = sprintf("SELECT Username FROM users WHERE Username=%s", GetSQLValueString($loginUsername, "text"));
mysql_select_db($database_localhost, $localhost);
$LoginRS=mysql_query($LoginRS__query, $localhost) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
//if there is a row in the database, the username was found - can not add the requested username
if($loginFoundUser){
$MM_qsChar = "?";
//append the username to the redirect page
if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&";
$MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar ."requsername=".$loginUsername;
header ("Location: $MM_dupKeyRedirect");
exit;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "registerForm")) {
$insertSQL = sprintf("INSERT INTO users (Fname, Lname, Username, Password, Email) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['Fname'], "text"),
GetSQLValueString($_POST['Lname'], "text"),
GetSQLValueString($_POST['Username'], "text"),
GetSQLValueString($_POST['password'], "text"),
GetSQLValueString($_POST['email'], "text"));
mysql_select_db($database_localhost, $localhost);
$Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());
}
mysql_select_db($database_localhost, $localhost);
$query_Register = "SELECT * FROM users";
$Register = mysql_query($query_Register, $localhost) or die(mysql_error());
$row_Register = mysql_fetch_assoc($Register);
$totalRows_Register = mysql_num_rows($Register);
?>
<?php
// *** Validate request to login to this site.
if (!isset($_SESSION)) {
session_start();
}
$loginFormAction = $_SERVER['PHP_SELF'];
if (isset($_GET['accesscheck'])) {
$_SESSION['PrevUrl'] = $_GET['accesscheck'];
}
if (isset($_POST['user'])) {
$loginUsername=$_POST['user'];
$password=$_POST['pwd'];
$MM_fldUserAuthorization = "";
$MM_redirectLoginSuccess = "members/lobby.php";
$MM_redirectLoginFailed = "index.php";
$MM_redirecttoReferrer = true;
mysql_select_db($database_localhost, $localhost);
$LoginRS__query=sprintf("SELECT Username, Password FROM users WHERE Username=%s AND Password=%s",
GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));
$LoginRS = mysql_query($LoginRS__query, $localhost) or die(mysql_error());
$loginFoundUser = mysql_num_rows($LoginRS);
if ($loginFoundUser) {
$loginStrGroup = "";
if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}
//declare two session variables and assign them
$_SESSION['MM_Username'] = $loginUsername;
$_SESSION['MM_UserGroup'] = $loginStrGroup;
if (isset($_SESSION['PrevUrl']) && true) {
$MM_redirectLoginSuccess = $_SESSION['PrevUrl'];
}
header("Location: " . $MM_redirectLoginSuccess );
}
else {
header("Location: ". $MM_redirectLoginFailed );
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<title>Yeti Draft</title>
<link href="css/bootstrap.css" rel="stylesheet">
<link rel="stylesheet" type="text/css" href="css/layout.css" >
<link rel="stylesheet" type="text/css" href="css/menu.css">
<script src="js/bootstrap.js" type="text/javascript"></script>
</head>
<body>
<div id = "container">
<div id = "navbar">
<nav>
<ul>
<div id = navStart>
<li><a href="#"><img src="images/logo.png"></a></li>
<li><a href="#">About</a></li>
<li><a href="#">Winners!</a></li>
<li><a href="#">Contact us</a></li>
<li><a href="#">FAQ</a></li></div>
<div id = "login"><li><a href="#loginModal" data-toggle="modal">Login</a></li>
<li class = "sign"><a href="#registerModal" data-toggle="modal">Sign Up</a></li>
</div>
</ul>
</nav>
</div>
<div id = "content">
</div>
<div id = "footer">
</div>
</div>
<!-- Login modal -->
<div class="modal fade" id="loginModal" aria-hidden="true">
<div class = "modal-dialog">
<div class = "modal-content">
<div class = "modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h3 class="modal-title">Login</h3>
</div>
<div class="modal-body">
<form ACTION="<?php echo $loginFormAction; ?>" METHOD="POST" id="loginForm">
<div class="form-group">
<label for="username">Username</label>
<input type="Username" class="form-control" id="user">
</div>
<div class="form-group">
<label for="pwd">Password:</label>
<input type="password" class="form-control" id="pwd">
</div>
<div class="checkbox">
<label><input type="checkbox"> Remember me</label>
</div>
</form>
</div>
<div class="modal-footer">
<button type="submit" class="btn btn-default" >Submit</button>
</div>
</div>
</div>
</div>
<!-- Register modal -->
<div class="modal fade" id="registerModal" aria-hidden="true">
<div class = "modal-dialog">
<div class = "modal-content">
<div class = "modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h3 class="modal-title">Sign Up</h3>
</div>
<div class="modal-body">
<form method="POST" action="<?php echo $editFormAction; ?>" name="registerForm" id="registerForm">
<h4>First Name: <br>
<input name="Fname" type="text" required="required" class="form-control" id="Fname">
</h4>
<h4>Last Name: <br>
<input name="Lname" type="text" required="required" class="form-control" id="Lname">
</h4>
<h4>Username:<br><input name="Username" type="text" required="required" class="form-control" id="Username">
</h4>
<h4>Email: <br><input name="email" type="email" required="required" class="form-control" id="email">
</h4>
<h4>Password:<br><input name="password" type="password" required="required" class="form-control" id="password">
</h4>
<h4>Confirm Password:<br><input type="password" required="required" class="form-control">
</h4>
<input type="hidden" name="MM_insert" value="registerForm">
</form>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary btn-lg" name="signup">Sign Up</button>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css">
</body>
</html>
<?php
mysql_free_result($Register);
?>
答案 0 :(得分:1)
更改button
的类型:
<button type="submit" class="btn btn-primary btn-lg" name="signup">Sign Up</button>
设置type="button"
会阻止表单发送。