0

我有一个不起作用的注册脚本。它曾经工作,但突然停止工作。我不知道我做了什么或发生了什么。我已经尝试了大约一个小时来找出问题所在,但我似乎无法找到它。

怎么了?当我单击注册时,我没有收到任何错误,但它没有上传到数据库:

当我输入时:$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");
    }
}
4

2 回答 2

1

I think you are getting the error because you are missing some quotes in your query for two columns wich really looks like not integers

'$email','$country',$rights,$IP,NOW())" //$rights and $ip doesn't have quotes 

so your query would look like

"insert into users(username,password,email,country,rights,IP,registrated)values('$username','$password','$email','$country','$rights','$IP',NOW())" 
于 2013-06-05T13:51:21.620 回答
1

使用 mysql_error() 来查看错误消息是什么。如果您没有更改脚本中的任何内容,那么要么是您的数据库结构已更改,要么是您的权限已更改。

更新:

您的 IP 值周围没有引号,这令人惊讶,因为您说该查询直到现在都有效。无论如何,您还应该考虑以正确的方式保存 IP 。祝你好运!

于 2013-06-05T13:46:50.283 回答