Copy link to clipboard
Copied
I'm creating a form that asks the user's e-mail address and stores it in a MySQL db. The e-mail address is a primary key and defined as "Unique". When I test with a duplicate e-mail address I get the correct error message "Duplicate entry 'a@t10.com' for key 1", I'd really like to make this a little more meaningful for the user - something like "Thanks but we've already received a reply from your e-mail address". Is there a way this can be changed - easily?
Thanks,
Tony Babb
Copy link to clipboard
Copied
You forgot to mention what scripting language you're using and supply your code!
Copy link to clipboard
Copied
oops, sorry. I should also have mentioned that the web site is for an airshow (www.hollisterairshow.com) and the form is a planning form to help us gauge likely attendance and can be found here www.hollisterairshow.com/helpusplan.php
I'm using DW CS4 with a MySQL db.
The db is set up with the e-mail column defined as a Primary key and Unique, In DW I use the Insert Record behavior, here's the PHP code DW generates.
Thanks.
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO plan (howArriving, howMany, Saturday, Sunday, camping, email, maillist, howHear) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['howarriving'], "text"),
GetSQLValueString($_POST['howMany'], "int"),
GetSQLValueString($_POST['whichdays'], "text"),
GetSQLValueString($_POST['whichdays'], "text"),
GetSQLValueString($_POST['RadioGroup1'], "text"),
GetSQLValueString($_POST['email'], "text"),
GetSQLValueString(isset($_POST['maillist']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString($_POST['howDidYouHear'], "text"));
mysql_select_db($database_planconnection, $planconnection);
$Result1 = mysql_query($insertSQL, $planconnection) or die(mysql_error());
}
Copy link to clipboard
Copied
Depending on your scripting language, you should be able to build an error handler that gets the message from the DBMS and sends a custom message to the visitor. As an aside, I would not use an email address as a primary key. I would make it a unique alternate key.
Copy link to clipboard
Copied
Re using e-mail as the primary key, this is a very basic application, we're trying to get an idea of how many people are likely to visit the airshow, how many cars or aircraft will have to be parked etc - it's totally unscientific but as this is the first airshow we've run it is better than anything else we have to gauge likely attendance. The e-mail address is there for two reasons:
1) We'd like to start building up a mail list for future airport promotions, there's an "opt-in" button following it
2) This will discourage some kid from entering the info multiple times as he'll have to enter different e-mail addresses each time.
Far from perfect I know, but probably adequate for our needs. I'll probably use the same approach for a feedback form that will be posted shortly and enabled immediately after the airshow.
Thanks