What does the mysqli_error() expects parameter 1 to be mysqli, null given mean?

后端 未结 4 1085
北恋
北恋 2020-11-30 13:19

I have this PHP page:



        
相关标签:
4条回答
  • 2020-11-30 13:40

    Book of Zeus already gave you the answer. This is for your future reference (and hopefully to help others in the future).

    It's helpful to learn to read error messages and try to figure out what might be causing them. :)

    This one tells you exactly what the problem is, and where to start looking.

    Warning: mysqli_error() expects parameter 1 to be mysqli, null given.
    

    The message tells you that the problem is parameter 1 provided to mysqli_error, and that it was null when mysqli_error expected it to be a mysqli.

    So look at the first parameter you're providing to mysqli_error, and you'll see it's $dbc. You know now that the problem is that $dbc is null when the call to mysqli_error() is made. So look at how it is that $dbc can be null. Oh, right - you didn't declare it and assign anything to it, because the first place it's used in the code is here:

    $code = mysqli_real_escape_string ($dbc, $_GET['invite']);
    

    and it's being used as if it's already something other than null. Since this is at the start of your code, the problem is that you forgot to declare and initialize it by connecting to the database. Problem solved. :)

    0 讨论(0)
  • 2020-11-30 13:40

    undefined variable $dbc in mysqli_error($dbc). you need to put your connection obj here.

    0 讨论(0)
  • 2020-11-30 13:47

    You need to define: $dbc before

     $code = mysqli_real_escape_string ($dbc, $_GET['invite']);
    

    ex:

    $dbc = mysqli_connect("localhost", "my_user", "my_password", "world");
    
    0 讨论(0)
  • 2020-11-30 13:47

    Hi please don't confuse with mysql_connect(); with mysqli_connect();

    Try to change as follows

    $conn=mysqli_connect("yourhost", "username", "password", "database-name") or die("initial host/db connection problem");`
    

    Then if its connected then pass your query with

    mysqli_query($conn, "your query string") or die ("query not executed");`
    

    Now it works fine! (mods, removed a to quer.r.y)

    0 讨论(0)
提交回复
热议问题