我收到了这两个错误:
警告:mysqli_query()需要至少2个参数,第11行/home/shadow28/public_html/register.php中给出的参数为1 警告:mysqli_num_rows()期望参数1为mysqli_result,在第12行的/home/shadow28/public_html/register.php中给出null 您的密钥无效,请联系支持部门。
这是register.php
<?PHP
require_once("include/config.php");
require('libs/Smarty.class.php');
$smarty = new Smarty;
$smarty->template_dir = 'templates';
$smarty->compile_dir = 'temp';
if(isset($_POST['username']) and ($_POST['password']) and ($_POST['key'])){
$username = $_POST['username'];
$password = md5($_POST['password']);
$key = $_POST['key'];
$query = mysqli_query("SELECT * FROM `keys` WHERE `key`='{$key}'");
if (mysqli_num_rows($query) == 1) {
while($row = mysql_fetch_array($query)){
$key1 = $row[0];
$months = $row[1];
$max = $row[2];
$type = $row[3];
}
if($months=="lifetime"){
$months = "lifetime";
}else{
$time = time();
$months = $time + 86400 * $months;
}
$query = mysql_query("INSERT INTO `users` (`login`, `passwd`, `max`, `attacks`, `expiry`, `type`, `key`) VALUES ('".$username."', '".$password."', '".$max."', '100', '".$months."', '".$type."', '{$key}');");
$query = mysql_query("delete from `keys` where `key`='{$key}'");
echo mysql_error();
$smarty->assign("done", "Your account has been added, you can now login.");
}else{
die("Your key isn't valid, please contact support.");
}
}else{
$smarty->assign("done", "");
}
$smarty->display("class.register.tpl");
?>
答案 0 :(得分:1)
mysqli
需要2个参数,第一个参数应为mysqli_connect()
$link = mysqli_connect("localhost", "dbuser", "dbpass", "dbname");
$query = mysqli_query($link, "SELECT * FROM 'keys' WHERE 'key'='{$key}'");
为什么使用mysql_
代替mysqli_
进行INSERT和DELETE查询?
如果您与mysql_connect()
关联,则不需要mysqli_query($link, "query")
,mysql_query("query")
请注意i
mysql