gpt4 book ai didi

javascript - PHP/SQL 上的无效表名错误

转载 作者:行者123 更新时间:2023-11-29 07:05:49 24 4
gpt4 key购买 nike

我网站上的注册页面显示错误消息:在数据库中注册新帐户时表名无效。

我的代码如下:

<?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>&nbsp;</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>&nbsp;</td>
</tr>
<tr>
<td><input type="submit" name="RegisterButton" id="RegisterButton" value="Register" /></td>
</tr>
<tr>
<td>&nbsp;</td>
</tr>
<tr>
<td>&nbsp;</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);
?>

感谢您尝试调试我的代码,非常感谢。

最佳答案

问题是

``user``

应该是

`user`
<小时/>

但是:你有一个更大的问题。不要使用 mysql_ 函数,因为它们不再包含在 PHP 中。您的代码在一年左右的时间内将无法工作。

查看 mysqliPDO .

关于javascript - PHP/SQL 上的无效表名错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41755325/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com