2015-06-20 80 views
-2

我不断收到这些错误:双mysqli_query()预计参数1是mysqli的,空给予警告

警告:mysqli_query()预计参数1是mysqli的,空给出 /家庭/ u590953899 /的public_html /应用程序/注册上线/ index.php的95

警告:mysqli_error()期望的是1个参数,0在 /home/u590953899/public_html/app/signup/index.php给出上线95

Line 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

我想通了....

上线即说:

$result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error());

应该$mysqli1而不是$mysqli因为$mysqli连接不存在

0

看起来您在提交的代码中将第3行的MySQLi连接命名为“$ mysqli1”,但您使用的是名为“$ mysqli”的变量作为mysqli_query函数中的第一个参数。

+0

我固定的但它仍然不起作用 –

+0

你仍然得到相同的错误?错误说$ mysqli为null,这意味着你必须确保mysqli_connect是正确的。 –