我有一个注册脚本不起作用。它曾经工作,但突然停止工作。我不知道我做了什么或发生了什么。我已经尝试了一个小时以找出问题所在,但我似乎无法找到它。注册script.php不起作用
会发生什么?当我点击注册我没有得到任何错误,但它不会上传到数据库中:当我键入
:$res = mysql_query($query) or die ("ERROR");
它显示ERROR
所以我认为这是相关代码:
//=============Configuring Server and Database=======
$host = 'localhost';
$user = 'root';
$password = '';
//=============Data Base Information=================
$database = 'login';
$conn = mysql_connect($host,$user,$password) or die('Server Information is not Correct'); //Establish Connection with Server
mysql_select_db($database,$conn) or die('Database Information is not correct');
//===============End Server Configuration============
//=============Starting Registration Script==========
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['pass1']);
$email = mysql_real_escape_string($_POST['email']);
$country = mysql_real_escape_string($_POST['country']);
$rights = '0';
$IP = $_SERVER['REMOTE_ADDR'];
//=============To Encrypt Password===================
//============New Variable of Password is Now with an Encrypted Value========
$query = mysql_query("SELECT username FROM users WHERE username = '".$username."'");
if (mysql_num_rows($query) > 0)
{
echo 'Username or email already in use.';
}
else{
if(isset($_POST['btnRegister'])) //===When I will Set the Button to 1 or Press Button to register
{
$query = "insert into users(username,password,email,country,rights,IP,registrated)values('$username','$password','$email','$country',$rights,$IP,NOW())" ;
$res = mysql_query($query);
header("location:load.php");
}
}
你可以总是尝试'mysql_query($ query)或死(mysql_error());'然后看看错误是什么。 – andrewsi
对于其中一个,我假设IP被写为VARCHAR,并且这个变量没有引号。在插入语句中。 '$ rights'也是如此。 – Eugene
仅供参考:'mysql_'查询已被弃用并打开SQL注入。改为使用'mysqli'。 –