Tengo el siguiente caso con el cual hago una insercion de registro en la BD
Código PHP:
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 reg_usr (mail, nombre, apellido, password, tipo_usr, fecha_in) VALUES (%s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['mail'], "text"),
GetSQLValueString($_POST['nombre'], "text"),
GetSQLValueString($_POST['apellido'], "text"),
GetSQLValueString($_POST['password'], "text"),
GetSQLValueString($_POST['tipo_usr'], "text"),
GetSQLValueString($_POST['fecha_in'], "date"));
mysql_select_db($database_conectar, $conectar);
$Result1 = mysql_query($insertSQL, $conectar) or die(mysql_error());
echo "pase por aqui";
echo mysql_error();
switch(mysql_errno())
{
case 1062:
echo "El correo electronico ingresado ya esta registrado en nuestra base de datos";
}
$insertGoTo = "usr.reg1.php?m=$mail";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
Cita:
Pero lo que quiero es que me aparezca un mensaje personalizado para este error... que estoy haciendo mal o en donde debo colocar el codigo para realizar esto ???Duplicate entry '[email protected]' for key 1
Muchas gracias.