2

When I use Netbeans to debug, the DELETION cannot be done because $test_affected_rows= mysqli_affected_rows($dbc) will return -1. This is strange becuase if I just run the script, the deletion runs good. When in Debug mode, mysqli_affected_rows($dbc) always returns -1 (it should be 1). What the heck is the cause?

require ('./mysqli_connect.php');

// Check if the form has been submitted:
if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    if ($_POST['sure'] == 'Yes') { // Delete the record.

        // Make the query:
        $q = "DELETE FROM users WHERE user_id=$id LIMIT 1";     
        $r = @mysqli_query ($dbc, $q);
                 $test_affected_rows= mysqli_affected_rows($dbc);
        if ($test_affected_rows == 1) { // If it ran OK.

            // Print a message:
            echo '<p>The user has been deleted.</p>';   

        } else { // If the query did not run OK.
            echo '<p class="error">The user could not be deleted due to a system error.</p>'; // Public message.
            echo '<p>' . mysqli_error($dbc) . '<br />Query: ' . $q . '</p>'; // Debugging message.
        }

    }

PS.I also tried to debug in Eclipse PHP, and met the same problem. So I guess it might be a MySQL problem?

0

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.