close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Check Unique Record - Display Result

Thread began 11/30/2010 7:32 am by CreateColl | Last modified 12/01/2010 6:26 am by Jason Byrnes | 2176 views | 7 replies |

CreateColl

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);
?>

Sign in to reply to this post

Jason ByrnesWebAssist

add your error message, then select it in design view. From the server behaviors panel, clci kthe plus button and select Validation Toolkit -> Validation Show If.


Select your validation from the list and then click ok.

Sign in to reply to this post

CreateColl

Ok, it's works fine.Thank you for your fast answer
here is the code to get inside the <body>

<?php
if (ValidatedField('1_862','1_862')) {
if ((strpos((",".ValidatedField("1_862","1_862").","), "," . "2" . ",") !== false || "2" == "")) {
if (!(false)) {
?>
message erreur
<?php //WAFV_Conditional 1.php 1_862( )
}
}
}?>

Sign in to reply to this post

Jason ByrnesWebAssist

glad to hear it is working.


the specific code will be unique for each page. That code will not be reusable by others.

Sign in to reply to this post

CreateColl

Juste two more thinks :
I builde with the server validation another condtion on the filde to check if this is a good email format :

<?php
if (isset($_POST["WA_Insert"])) {
$WAFV_Redirect = "";
$_SESSION['WAVT_Checkuniquekey_859_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateEM(((isset($_POST["email"]))?$_POST["email"]:"") . "",true,1);

if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"Checkuniquekey_859");
}
}
?>

it's works good -)))

But when a build the validation if (inside the body) for this second condition, the code take 1_862( from the 1st condition server) instade of Checkuniquekey_859(2nd cond server) . Juste a remark for your developper. It take only ten second to adjust.-

And another think about the display message : it stay display even if we refresh the page or repost !

Do we have to kill the session ? or something else because with a multiple form filed it could be annoying for the user.

Sign in to reply to this post

Jason ByrnesWebAssist

do not add separate server behavior for each validation, use the same server validation server behavior instead.

Sign in to reply to this post

CreateColl

Thanks Jason
it's work fin

Sign in to reply to this post

Jason ByrnesWebAssist

You're welcome.

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...