Hi,

I am not sure which mysqli error reporting function to use here.
Which of the two is correct ?

if(!mysqli_stmt_prepare($stmt,$sql_count))
    {
        echo __LINE__; echo '<br>';//DELETE

        echo 'Mysqli Error: ' .mysqli_stmt_error(); //DEV MODE.
        echo '<br>';
        echo 'Mysqli Error No: ' .mysqli_stmt_errno(); //DEV MODE.
        echo '<br>';
        die('Registration a Failure!');
}
if(!mysqli_stmt_prepare($stmt,$sql_count))
    {
        echo __LINE__; echo '<br>';//DELETE

        echo 'Mysqli Error: ' .mysqli_error(); //DEV MODE.
        echo '<br>';
        echo 'Mysqli Error No: ' .mysqli_errno(); //DEV MODE.
        echo '<br>';
        die('Registration a Failure!');
}

Recommended Answers

All 7 Replies

@Dani

You have a bug in your forum.
Can you see there are two numbered "1" above (my original post) in your browser ? Using Fire Fox latest.
The 2nd number is supposed to be "2". I wrote "2" and not "1". Nevertheless, I edited the post many times but Fire Fox still showing as "1" while in the EDIT page it shows as "2".
Refreshed browser (reloaded page) many times. No luck.

Hello! Thank you for posting this.

Here at DaniWeb, we use the Markdown syntax for posting. (You can get to that page I just linked to by clicking the little question mark in the editor toolbar).

If you scroll down that page to where it says Lists, you can see:

Optionally, if you'd like to be lazy, as long as you start your list with 1. , Markdown will keep track of the line number for you, so you can prefix every line with 1. , for example.

This is a feature of the Markdown language, and not my own invention. The correct way to generate:

  1. Code Block 1:

     if(!mysqli_stmt_prepare($stmt,$sql_count))
         {
             echo __LINE__; echo '<br>';//DELETE
    
             echo 'Mysqli Error: ' .mysqli_stmt_error(); //DEV MODE.
             echo '<br>';
             echo 'Mysqli Error No: ' .mysqli_stmt_errno(); //DEV MODE.
             echo '<br>';
             die('Registration a Failure!');
     }
  2. Code block 2:

     if(!mysqli_stmt_prepare($stmt,$sql_count))
         {
             echo __LINE__; echo '<br>';//DELETE
    
             echo 'Mysqli Error: ' .mysqli_error(); //DEV MODE.
             echo '<br>';
             echo 'Mysqli Error No: ' .mysqli_errno(); //DEV MODE.
             echo '<br>';
             die('Registration a Failure!');
     }

Is as the following:

1. Code Block 1:

        if(!mysqli_stmt_prepare($stmt,$sql_count))
            {
                echo __LINE__; echo '<br>';//DELETE

                echo 'Mysqli Error: ' .mysqli_stmt_error(); //DEV MODE.
                echo '<br>';
                echo 'Mysqli Error No: ' .mysqli_stmt_errno(); //DEV MODE.
                echo '<br>';
                die('Registration a Failure!');
        }


1. Code block 2:

        if(!mysqli_stmt_prepare($stmt,$sql_count))
            {
                echo __LINE__; echo '<br>';//DELETE

                echo 'Mysqli Error: ' .mysqli_error(); //DEV MODE.
                echo '<br>';
                echo 'Mysqli Error No: ' .mysqli_errno(); //DEV MODE.
                echo '<br>';
                die('Registration a Failure!');
        }

While code should normally be intended by either 4 spaces or one tab stop, code within a list should be indented by two tab stops. By not doing this, you were making your code block not recognized as part of item 1 of the list, and therefore ended your list right before your first code block, and started a brand new list, only to end it prematurely right before your second code block.

mysqli_error() refers to the last MySQLi function call of any type. mysqli_stmt_error() refers to the last MySQLi statement (an INSERT, DELETE, UPDATE, SELECT, etc.). This is just a stab in the dark, but my guess is that the difference is that mysqli_error() will also error on connection failures, while mysqli_stmt_error() will not.

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

That sounds a lot like what I just said :)

@Dani

Sticking to this:

if(!mysqli_stmt_prepare($stmt,$sql_count))
    {
        echo __LINE__; echo '<br>';//DELETE

        echo 'Mysqli Error: ' .mysqli_stmt_error(); //DEV MODE.
        echo '<br>';
        echo 'Mysqli Error No: ' .mysqli_stmt_errno(); //DEV MODE.
        echo '<br>';
        die('Registration a Failure!');
}

If that is fine then do close this thread.

Thanks!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.