Jump to content

Error Reporting


TapeGun007
Go to solution Solved by mac_gyver,

Recommended Posts

I'm trying to figure out my bug here, and I what I really want to know is how to debug my own code which would result in less posting here.  Also it would be nice to contribute and help others as I learn from my mistakes.

 

I have this code:

 

 

mysqli_report(MYSQLI_REPORT_ALL);

 

This is near the top of my code after all the include files.

 

Then below after a form I have this code:

 

        $sql = "INSERT INTO Prospects 
                                (ProspectCode,
                                ProspectBusinessName,
                                ProspectName,
                                ProspectAddress,
                                ProspectAddress2,
                                ProspectCity,
                                ProspectState,
                                ProspectZip,
                                ProspectCounty,
                                ProspectCountry) 
                                VALUES (?,?,?,?,?,?,?,?,?,?)";
        // Check $sql to ensure it's correct
        echo "<p>$sql</p>";
        
        /* Prepared statement, stage 1: prepare */
        if (!($stmt = $con->prepare($sql))) {
            echo "Prepare failed: (" . $con->errno . ") " . $con->error;
        }
 
        // Bind parameters, stage 2. Types: s = string, i = integer, d = double,  b = blob
        if (!$stmt->bind_param('ssssssssss', $ReferralCode, $Business, $Contact, $Address, $Address2, $City, $State, $Zip, $County, $Country)) {
            echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
        }
        // Execute.  stage 3
        if (!$stmt->execute()) {
            echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
        }

 

I'm trying to error check, so I could debug it myself, but there is no error.  Weirdly enough, it worked fine up until I added County and Country.

 

*sigh*  It's probably some very simple syntax error, but how come it doesn't produce an error so I can troubleshoot the problem?

 

 

 

 

Link to comment
Share on other sites

  • Solution

with the mysqli_report set, all that will do is reporting errors/throw exceptions. to display or handle the reported errors, you need to either put a try/catch block around your code and handle the thrown error yourself, or you need to have php's error_reporting set to E_ALL and display_errors set to ON so that the reported mysqli errors or the uncaught exception will be reported and displayed.

Link to comment
Share on other sites

Thanks mac_gyver.  I did my homework on what you said as I wasn't sure where to set this.

 

I used this to do it for now and will set it back later.

ini_set("display_errors", 1);
ini_set("track_errors", 1);
ini_set("html_errors", 1);
error_reporting(E_ALL);

[/cdoe]

 

That gave me the error I was looking for on another page and was able to quickly resolve the issue.

Edited by TapeGun007
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.