我花了好几个小时试图找出为什么我无法获取代码以防止重复文件进入我的数据库。任何帮助将不胜感激。谢谢!
<?php
if(isset($_POST['Register']))
{
session_start();
$sql=mysql_query("SELECT UserName FROM BD WHERE UserName='$UName'");
if(mysql_num_rows($sql)>=1)
{
echo"name already exists";
}
else
{
$FName = $con->real_escape_string($_POST['FirstName']);
$LName = $con->real_escape_string($_POST['LastName']);
$Email = $con->real_escape_string($_POST['Email']);
$UName = $con->real_escape_string($_POST["UserName"]);
$PW = $con->real_escape_string($_POST["Password"]);
$sql = $con->query("INSERT INTO BD (FirstName, LastName, Email, UserName, Password) Values('{$FName}', '{$LName}', '{$Email}', '{$UName}','{$PW}')");
header('Location: login.php');
}
}
?>
答案 0 :(得分:0)
首先检查您的会话是否正常运行....使用&#39; echo $ UName;&#39;在上面的代码,如果它显示任何东西......
答案 1 :(得分:0)
似乎你要求mysqli(改进版的mysql),但你实际上是在使用旧的mysql_query和mysql_num_rows命令。尝试用正确的语法替换mysqli_query和mysqli_num_rows,看看它是否有效..