Displaying MySQL errors on the same page with php.
Posted: Tue Apr 27, 2010 11:11 am
Hi,
I have a page which in essence is used register new users. It contains multiple form input type fields, such as first name, last name, and account id.
Currently I'm using php to check if the account id in the form has a duplicate in the database, and if so to return a error message. This is working, however the mysql error is being displayed on a blank white page on submit, because I haven't specified for it to do anything else.
I'd like to have the mysql duplicate key error display on the same page as the form like a validation message.
This is how I display my error:
I'm still very new to all of this, so any insight would be greatly appreciated.
Thanks!
I have a page which in essence is used register new users. It contains multiple form input type fields, such as first name, last name, and account id.
Currently I'm using php to check if the account id in the form has a duplicate in the database, and if so to return a error message. This is working, however the mysql error is being displayed on a blank white page on submit, because I haven't specified for it to do anything else.
I'd like to have the mysql duplicate key error display on the same page as the form like a validation message.
This is how I display my error:
Code: Select all
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO tblcustomeraccount (Points, AccountId) VALUES (%s, %s)",
GetSQLValueString($_POST['Points'], "int"),
GetSQLValueString($_POST['AccountId'], "int"));
mysql_select_db($database_connDB, $connDB);
$Result1 = mysql_query($insertSQL, $connDB) or die('<b>An error occurred because:</b> ' . mysql_error());
Thanks!