注册script.php不起作用
我的注册脚本不起作用。它过去可以工作,但后来突然停止了工作。我不知道我做了什么或发生了什么。我已经试了大约一个小时来找出问题所在,但似乎找不到 会发生什么?单击“注册”时,我没有收到任何错误,但它不会上载到数据库: 当我输入:注册script.php不起作用,php,mysql,database,Php,Mysql,Database,我的注册脚本不起作用。它过去可以工作,但后来突然停止了工作。我不知道我做了什么或发生了什么。我已经试了大约一个小时来找出问题所在,但似乎找不到 会发生什么?单击“注册”时,我没有收到任何错误,但它不会上载到数据库: 当我输入:$res=mysql\u query($query)或die(“ERROR”)它显示错误,因此我认为它与该代码有关: //=============Configuring Server and Database======= $host = 'local
$res=mysql\u query($query)或die(“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_error()查看错误消息。如果脚本中没有任何更改,则可能是数据库结构已更改或权限已更改
更新:
您的IP值周围没有引号,这是令人惊讶的,因为您说该查询一直有效到现在。无论如何,你也应该考虑节约IPS。祝你好运 我认为您得到了错误,因为您在查询中缺少了两列的引号,这两列看起来确实不是整数
'$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())"
您可以尝试使用mysql\u query($query)或die(mysql\u error())
并查看实际错误是什么。对于其中一个错误,我假设IP是作为VARCHAR编写的,并且在insert语句中该变量周围没有引号$rights
以及。仅供参考:mysql\
查询已被弃用,并对SQL注入开放。改为使用mysqli
。您好。感谢您重播PHP_nub-qq。它说:您的SQL语法有错误;请查看与MySQL服务器版本对应的手册,以了解应在第1ip行(可能是字符串)的“.100.179,NOW())”附近使用的正确语法。您的IP值周围没有引号,这是令人惊讶的,因为您说查询一直有效。无论如何,你也应该考虑节约IPS。祝你好运谢谢你们的帮助!我找到了。。我错过了一些qoutes--我要5分钟才能接受!但是嘿!谢谢法比奥!:)它起作用了。。。我本应该看到的--但是谢谢!:)