mysqli_error() expects exactly 1 parameter, 0 give

2019-09-01 07:43发布

问题:

I'm having an issues with my code in php...

mysqli_error() expects exactly 1 parameter, 0 given in on line 63. Im getting 8 of these errors.

Here is line 63: --die('Error: ' . mysqli_error());--

Here is the function it is in:

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>";

How can I fix this issue?

EDIT FULL SCRIPT

<?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:

try this.

mysqli_error($con);

or replace $con with which ever variable holds the connection handle

(edit: replace $con with $link in your case)

"The mysqli_error() function returns the last error description for the most recent function call, if any."