Check Unique Record - Display Result
Hello
I read the forum to understand how to check an unique key in a table whan I use an insert transaction. I succeed it with the following code ( excuse for the length but we can make link in your forum).
Now, I would like to know how we can display the result ( in the same page ) like a message
'Duplicate record'.
Do we have to use the $_SESSION['WAVT_1_862_Errors'] with "echo $_SESSION['WAVT_1_862_Errors']"
Or $WAFV_Errors ?
because I don't know exactly what
PostResult($WAFV_Redirect,$WAFV_Errors,"1_862");
returne ?
Thank for your replay
G.S
<?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;
}
}
?>
<?php
$colname_CHECK_UNIQUE_MAIL = "-1";
if (isset($_POST['email'])) {
$colname_CHECK_UNIQUE_MAIL = (get_magic_quotes_gpc()) ? $_POST['email'] : addslashes($_POST['email']);
}
mysql_select_db($database_CNX, $CNX);
$query_CHECK_UNIQUE_MAIL = sprintf("SELECT * FROM sdd_membre WHERE MAIL = %s", GetSQLValueString($colname_CHECK_UNIQUE_MAIL, "text"));
$CHECK_UNIQUE_MAIL = mysql_query($query_CHECK_UNIQUE_MAIL, $CNX) or die(mysql_error());
$row_CHECK_UNIQUE_MAIL = mysql_fetch_assoc($CHECK_UNIQUE_MAIL);
$totalRows_CHECK_UNIQUE_MAIL = mysql_num_rows($CHECK_UNIQUE_MAIL);
?>
<?php
if (isset($_POST["WA_Insert"])) {
$WAFV_Redirect = "";
$_SESSION['WAVT_1_862_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateNM($totalRows_CHECK_UNIQUE_MAIL . "",-1,0,0,".,",true,2);
if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"1_862");
}
}
?>
<?php
// WA Application Builder Insert
if (isset($_POST["WA_Insert"])) // Trigger
{
$WA_connection = $CNX;
$WA_table = "sdd_membre";
$WA_sessionName = "id_memb";
$WA_redirectURL = "";
$WA_keepQueryString = false;
$WA_indexField = "id_memb";
$WA_fieldNamesStr = "MAIL";
$WA_fieldValuesStr = "".((isset($_POST["email"]))?$_POST["email"]:"") ."";
$WA_columnTypesStr = "',none,''";
$WA_fieldNames = explode("|", $WA_fieldNamesStr);
$WA_fieldValues = explode("|", $WA_fieldValuesStr);
$WA_columns = explode("|", $WA_columnTypesStr);
$WA_connectionDB = $database_CNX;
mysql_select_db($WA_connectionDB, $WA_connection);
if (!session_id()) session_start();
$insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
$WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
$MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
$_SESSION[$WA_sessionName] = mysql_insert_id();
if ($WA_redirectURL != "") {
if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
$WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
}
header("Location: ".$WA_redirectURL);
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="../../../Styles/form_clean.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form action="<?php echo((isset($_SERVER["PHP_SELF"]))?$_SERVER["PHP_SELF"]:"") ?>" method="post" class="clean" id="form1">
<ol>
<li>
<fieldset>
<ol>
<li>
<label for="email">EMAIL</label>
<input type="text" id="email" name="email" value="" />
</li>
</ol>
</fieldset>
</li>
</ol>
<p style="text-align:right;">
<input type="reset" value="CANCEL" />
<input name="WA_Insert" type="submit" id="WA_Insert" value="OK" />
</p>
</form>
</body>
</html>
<?php
mysql_free_result($CHECK_UNIQUE_MAIL);
?>