Handle Database Error in PHP

you get an error saying that foreign key integrity has been violated, and the insert fails

note you can catch the error in php and issue your own user-friendly error message (but don’t ask me how to do that, as i don’t do php)[/quote]

Can someone help me figure this one out?

Since I use Prepared Statements, would I capture it like below…


			// Verify Insert.
			if (mysqli_stmt_affected_rows($stmt3)==1){
				// Insert Succeeded.
				do something...
			}else{
				// Insert Failed.
				$_SESSION['resultsCode'] = 'ACCOUNT_MEMBER_ACCT_FAILED_2103';
			}// End of VERIFY INSERT.

			// Close prepared statement.
			mysqli_stmt_close($stmt2);

			// Set Error Source.
			$_SESSION['errorPage'] = $_SERVER['SCRIPT_NAME'];

			// Redirect to Display Outcome.
			header("Location: " . BASE_URL . "/account/results.php");

			// End script.
			exit();
		}else{
			// Invalid form data.
			// Drop through to display Form.
		}//End of ATTEMPT TO CREATE MEMBER

Thanks,

Debbie

There’s a difference between an insert failing (0 affected rows), and an ERROR.

if it’s an error, mysqli_error() would hold the text contents of the error.
mysqli_errno() would hold the error number (as specified by the MySQL Error Codes)