mysqli_error()期望在第63行中给出1个参数0

时间:2015-03-16 06:11:34

标签: php mysqli error-handling

我在php中遇到了代码问题...

mysqli_error()期望在第63行给出1个参数,0。我得到了8个这样的错误。

这是第63行: - 'die('错误:'。mysqli_error()); -

这是它的功能:

if($email_exists == false && $pass1 == $pass2)
        {
            $sql="INSERT INTO users(u_Fname, u_Lname, u_email, u_Password)
                VALUES('$Fname', '$Lname', '$EmailAddress', '$Password')";

            if(!mysqli_query($link, $sql))
            {
                #$query = mysqli_query($myConnection, $sqlCommand);
                #die (mysqli_error($myConnection));
                die('Error: ' . mysqli_error());

            }
            header("location: login.php");
        }
        echo "<hr>";

如何解决此问题?

编辑全文

<?php 
session_start();
require_once('connect.php');
require_once "utils.php";

if(isset($_POST['submit']))
{
    //CHECK EMPTY FORM DATA and SANITIZE
    if(!empty($_POST['Username'])&&
       !empty($_POST['Fname'])&& 
       !empty($_POST['Lname'])&& 
       !empty($_POST['EmailAddress'])&& 
       !empty($_POST['Password'])&& 
       !empty($_POST['Password1']))
    {
        $Username = mysqli_real_escape_string($link,htmlentities($_POST['Username']));
        $Fname = mysqli_real_escape_string($link,htmlentities($_POST['Fname']));
        $Lname = mysqli_real_escape_string($link,htmlentities($_POST['Lname']));
        $Password = mysqli_real_escape_string($link,htmlentities($_POST['Password']));
        $Password1 = mysqli_real_escape_string($link,htmlentities($_POST['Password1']));
        $EmailAddress = mysqli_real_escape_string($link,htmlentities($_POST['EmailAddress']));
    }

    else { header("Location: register.php");exit(); }

        if(isset($EmailAddress) && !empty($EmailAddress) &&
           isset($Password) && !empty($Password))
        {
            $email_exists = false;

            $sql="SELECT * FROM users WHERE u_EmailAddress='$EmailAddress'";

            if($result = mysqli_query($link, $sql))
            {
                while($record = mysqli_fetch_row($result))
                {
                    if($record = $EmailAddress)
                    {
                        $email_exists = true;
                    }

                    if($email_exists = true)
                    {
                        echo "<div id='reg_error1'>* The Email Used Already Exists! <br></div>";
                    }
                }
            }

            if($Password != $Password1)
            {
                echo "<div id='reg_error2'>* Your Password Does Not Match!<br></div>";
            }

            if($email_exists == false && $Password == $Password1)
            {
                $sql="INSERT INTO users(u_Username, u_Fname, u_Lname, u_EmailAddress, u_Password)
                VALUES('$_POST[$Username]', '$_POST[$Fname]', '$_POST[$Lname]', '$_POST[$EmailAddress]', '$_POST[$Password]')";
                echo "<pre>"; print_r($sql); exit;
                if(!mysqli_query($link, $sql))
                {
                    #$query = mysqli_query($myConnection, $sqlCommand);
                    #die (mysqli_error($myConnection));
                    die('Error: ' . mysqli_error($link));               
                }
                header("location: login.php");
            }
            echo "<hr>";
        }
}

1 个答案:

答案 0 :(得分:1)

试试这个。

mysqli_error($ CON);

或替换$ con,其变量包含连接句柄

(编辑:在你的情况下用$ link替换$ con)

&#34; mysqli_error()函数返回最近一次函数调用的最后一个错误描述(如果有的话)。&#34;