0
我的註冊頁面顯示錯誤消息。無效的表名錯誤在我的網站
我的代碼如下:
<?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="Register.php";
$loginUsername = $_POST['UserName2'];
$LoginRS__query = sprintf("SELECT Username FROM `user` 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 ``user`` (Fname, Lname, Email, Username, Password) VALUES (%s, %s, %s, %s, %s)",
GetSQLValueString($_POST['FName'], "text"),
GetSQLValueString($_POST['LName'], "text"),
GetSQLValueString($_POST['Email'], "text"),
GetSQLValueString($_POST['UserName2'], "text"),
GetSQLValueString($_POST['Password'], "text"));
mysql_select_db($database_localhost, $localhost);
$Result1 = mysql_query($insertSQL, $localhost) or die(mysql_error());
$insertGoTo = "Login.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_localhost, $localhost);
$query_Register = "SELECT * FROM `user`";
$Register = mysql_query($query_Register, $localhost) or die(mysql_error());
$row_Register = mysql_fetch_assoc($Register);
$totalRows_Register = mysql_num_rows($Register);
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script src="SpryAssets/SpryValidationTextField.js" type="text/javascript"></script><script src="SpryAssets/SpryValidationConfirm.js" type="text/javascript"></script>
<script src="SpryAssets/SpryValidationPassword.js" type="text/javascript"></script>
<link href="SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationConfirm.css" rel="stylesheet" type="text/css" />
<link href="SpryAssets/SpryValidationPassword.css" rel="stylesheet" type="text/css" />
</head>
<link href="CSS/layout.css" rel="stylesheet" type="text/css" />
<link href="CSS/menu.css" rel="stylesheet" type="text/css" />
<body>
<div id="Holder"></div>
<div id="Header"></div>
<div id="NavBar">
<nav>
<ul>
<li><a href="Login.php">Login</a></li>
<li><a href="Register.php">Register</a></li>
<li><a href="ForgotPassword.php">Forgot Password</a></li>
</ul>
</nav>
</div>
<div id="Content"></div>
<div id="ContentLeft">
<h1>Sign Up!</h1>
</div>
<div id="ContentRight">
<form id="RegisterForm" name="RegisterForm" method="POST" action="<?php echo $editFormAction; ?>">
<table width="400" border="1" align="center">
<tr>
<td><table border="1">
<tr>
<td><h6><span id="sprytextfield1">
<label for="FName"></label>
<input type="text" name="FName" id="FName" />
<br />
First Name: </span></h6>
<span><span class="textfieldRequiredMsg">A value is required.</span></span></td>
<td><h6><span id="sprytextfield2">
<label for="LName"></label>
<input type="text" name="LName" id="LName" />
<br />
Last Name: </span></h6>
<span><span class="textfieldRequiredMsg">A value is required. </span></span></td>
</tr>
</table></td>
</tr>
<tr>
<td><h6 class="StyleTxtField">Email:
<input name="Email" type="text" id="Email" />
</h6></td>
</tr>
<tr>
<td><span id="sprytextfield3">
<label for="Email"></label>
<span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span></td>
</tr>
<tr>
<td><h6 class="StyleTxtField">UserName:
<input name="UserName2" type="text" id="UserName2" />
</h6></td>
</tr>
<tr>
<td><span id="sprytextfield4">
<label for="UserName"></label>
<span class="textfieldRequiredMsg">A value is required.</span></span> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><table border="1">
<tr>
<td><h6 class="StyleTxtField">Password:<span id="sprypassword1">
<label for="Password"></label>
<input name="Password" type="password" class="StyleTxtField" id="Password" />
<span class="passwordRequiredMsg">A value is required.</span></span></h6></td>
<td><h6><span class="StyleTxtField" id="spryconfirm1">
<label for="PasswordConfirm"></label>
<br />
Confirm Password:<br />
<input name="PasswordConfirm" type="password" class="StyleTxtField" id="PasswordConfirm" />
<br />
<br />
: </span></h6>
<span><span class="confirmRequiredMsg">A value is required.</span><span class="confirmInvalidMsg">The values don't match.</span></span></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td><input type="submit" name="RegisterButton" id="RegisterButton" value="Register" /></td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td height="25"><table border="1">
<tr> </tr>
</table></td>
</tr>
<tr> </tr>
<tr> </tr>
<tr>
<td height="24"><table border="1">
<tr> </tr>
</table></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="RegisterForm" />
</form>
</div>
<div id="Footer"></div>
</div>
<script type="text/javascript">
var sprytextfield4 = new Spry.Widget.ValidationTextField("sprytextfield4");
var sprytextfield3 = new Spry.Widget.ValidationTextField("sprytextfield3", "email");
var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
var spryconfirm1 = new Spry.Widget.ValidationConfirm("spryconfirm1", "Password");
var sprypassword1 = new Spry.Widget.ValidationPassword("sprypassword1");
</script>
</body>
</html>
<?php
mysql_free_result($Register);
?>
感謝您嘗試調試我的代碼,你都大爲讚賞。
這是調試代碼的一個步驟:在將它作爲SQL語句提交給數據庫之前,輸出'$ insertSQL'字符串的值。 (如果你沒有日誌記錄功能,只需用'echo'或'vardump')。一旦你用SQL語句找出問題,你可以修改代碼。 (順便說一下... StackOverflow是*不*調試服務。https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) – spencer7593
謝謝你,我肯定在將來使用它! –