我一直收到这些错误:
警告:mysqli_query()期望参数1为mysqli,null给定 在/home/u590953899/public_html/app/signup/index.php第95行
警告:mysqli_error()正好需要1个参数,给出0 第95行/home/u590953899/public_html/app/signup/index.php
第95行是:
$result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error());
整个代码:
<?php
session_start();
$mysqli1=mysqli_connect('localhost','u590953899_staff','DCr102404$','u590953899_dev') or die("Database Error");
if(isset($_POST['submit']))
{
//whether the username is blank
if($_POST['username'] == '')
{
$_SESSION['error']['username'] = "User Name is required.";
}
else
{
//if it has the correct format whether the email has already exist
$username= $_POST['username'];
$sql1 = "SELECT * FROM user WHERE username = '$username'";
$result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error());
if (mysqli_num_rows($result1) > 0)
{
$_SESSION['error']['username'] = "This username is already taken.";
}
}
//whether the email is blank
if($_POST['email'] == '')
{
$_SESSION['error']['email'] = "E-mail is required.";
}
else
{
if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/", $_POST['email']))
{
//if it has the correct format whether the email has already exist
$email= $_POST['email'];
$sql1 = "SELECT * FROM user WHERE email = '$email'";
$result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error());
if (mysqli_num_rows($result1) > 0)
{
$_SESSION['error']['email'] = "This Email is already used.";
}
}
else
{
//this error will set if the email format is not correct
$_SESSION['error']['email'] = "Your email is not valid.";
}
}
//whether the password is blank
if($_POST['password'] == '')
{
$_SESSION['error']['password'] = "Password is required.";
}
//if the error exist, we will go to registration form
if(isset($_SESSION['error']))
{
header("Location: http://app.bithumor.co/signup/");
exit;
}
else
{
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$com_code = md5(uniqid(rand()));
$ip = $_SERVER['REMOTE_ADDR'];
$sql2 = "INSERT INTO user (username, email, password, com_code) VALUES ('$username', '$email', '$password', '$com_code')";
$result2 = mysqli_query($mysqli1,$sql2) or die(mysqli_error());
我到处寻找解释/解决方案,但没有任何工作。
答案 0 :(得分:0)
看起来您在提交的代码中第3行命名了MySQLi连接“$ mysqli1”,但是您使用名为“$ mysqli”的变量作为mysqli_query函数中的第一个参数。
答案 1 :(得分:0)
我想通了......
在说:
的行上 if ([entry[@"isInactive"] boolValue])
{ // Original
dispatch_async(dispatch_get_main_queue(), ^{
self.profileIconShadow.layer.shadowColor = [UIColor redColor].CGColor;
[self.profileIconShadow.layer setNeedsDisplay];
}
}
应该是$result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error());
而不是$mysqli1
,因为$mysqli
连接不存在