注册script.php不起作用

时间:2013-06-05 13:43:58

标签: php mysql database

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

会发生什么?当我点击注册时,我没有收到任何错误,但它没有上传到数据库:

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

2 个答案:

答案 0 :(得分:1)

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

更新

您的IP值没有引号,这是令人惊讶的,因为您说该查询到目前为止一直有效。无论如何,您还应该考虑将RIGHT way保存为IP。祝你好运!

答案 1 :(得分:1)

我认为你收到了错误,因为你在查询中遗漏了两个真正看起来不是整数的列的引号

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

所以你的查询看起来像是

"insert into users(username,password,email,country,rights,IP,registrated)values('$username','$password','$email','$country','$rights','$IP',NOW())" 
相关问题