PDA

View Full Version : Trying to Avoid duplicate entries


mustang_sally_85344510
05-09-2009, 09:46 PM
Hello,
I was wondering how to avoid a dupicate entry into a DB.? For example, I have a table that I want a user to only be able to enter data into ONCE.
Which WA extention would be best for this. I have WA Supersuite.
I would like to check/validate the database by visitorID.

Thank you in advance for steering me in the right direction! :)

Ian
05-11-2009, 03:05 AM
Is VisitorID the unique ID for the table? If so, it should be set to auto increment anyway.

However, if Visitor ID is another field in the table then the best way to do this is call a recordset on "Post" of the form against the values in the form, check to see if the recordset is populated. If it is then present an error and if it isnt then use Data Assist to insert the record.

I might be wrong but I dont think Data Assist will do all this for you - you need to do a bit of manual coding to acheive the result.

Cheers
Ian

mustang_sally_85344510
05-11-2009, 08:17 AM
visitorID is NOT the unique ID in this particular table. Is is NOT the autoincrement field. I don't remember DATAASSIST asking for compare to variables....I do however recall SecurityAssist asking for what compare to variables...? Thank you for your input, and I'll give it a try! :)

Ray Borduin
05-11-2009, 09:04 AM
I would create a recordset filtered by the id and use validation toolkit to validate that no records are returned from that recordset.

mustang_sally_85344510
05-11-2009, 09:57 AM
when if filter the recordset...specifically...could you please give me the exact language to filter? My insert record has the "hidden" value for the visitorID, which is carried by the loginvisitorID,...so do I used the visitorID session variable, entered value or what? I do appreciate your help! :)

Ray Borduin
05-11-2009, 10:00 AM
Filter using the simple recordset wizard. Filter from the submitted form element based on the field that you want to ensure is unique.

The first step is to create the recordset that shoudl return no results if there are no repeats and one result if there are repeats.

mustang_sally_85344510
05-11-2009, 10:46 AM
Was wondering...
Does it make any difference if I have "Security Assist Access to page" applied to the same page? as, I do...

Ray Borduin
05-11-2009, 10:55 AM
It shouldn't but I guess it depends on your workflow and settings. It won't interfere directly, but it could cause an unrelated problem that could be confusing.

Maybe remove the restrict access server behavior if you think it might be causing issues and add it back once everything else is working.

mustang_sally_85344510
05-11-2009, 11:48 AM
Hi again,
I removed page access...At this point nothing can be entered.
Here is VALADATION code.
<?php
if (isset($_POST["submitcenter"])) {
$WAFV_Redirect = "alreadyentered.php";
$_SESSION['WAVT_centerinput_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateNM($row_rsverify['VisitorID'] . "",0,0,"",",.",true,1);

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

Here is recordset code:
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$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;
}
}

$colname_rsverify = "-1";
if (isset($_POST[''])) {
$colname_rsverify = (get_magic_quotes_gpc()) ? $_POST[''] : addslashes($_POST['']);
}
mysql_select_db($database_bowlingtournaments, $bowlingtournaments);
$query_rsverify = sprintf("SELECT VisitorID FROM centers WHERE VisitorID = %s", GetSQLValueString($colname_rsverify, "text"));
$rsverify = mysql_query($query_rsverify, $bowlingtournaments) or die(mysql_error());
$row_rsverify = mysql_fetch_assoc($rsverify);
$totalRows_rsverify = mysql_num_rows($rsverify);
?>

Ray Borduin
05-11-2009, 12:31 PM
Make sure to move the recordset code above the validation code, and the line:

$WAFV_Errors .= WAValidateNM($row_rsverify['VisitorID'] . "",0,0,"",",.",true,1);

should be:

$WAFV_Errors .= WAValidateNM($totalRows_rsverify . "",0,0,"",",.",true,1);

mustang_sally_85344510
05-11-2009, 12:58 PM
:( Still doesn't work. :(
Can it be that I am using a hidden form element? that enters the visitorID when the form is submitted?

Ray Borduin
05-11-2009, 02:37 PM
if (isset($_POST[''])) {
$colname_rsverify = (get_magic_quotes_gpc()) ? $_POST[''] : addslashes($_POST['']);
}

should be:
if (isset($_POST['formElementName'])) {
$colname_rsverify = (get_magic_quotes_gpc()) ? $_POST['formElementName'] : addslashes($_POST['formElementName']);
}

mustang_sally_85344510
05-12-2009, 09:29 AM
:( It still won't allow any entries at this point :(
Would it be better to maybe used "on page load" feature...instead of button submit?
I'm going to try a few more times, then submit a support ticket with all my code....

Ray Borduin
05-12-2009, 09:34 AM
I'm not sure how it could work on page load. I think submit is the correct trigger.

mustang_sally_85344510
05-12-2009, 10:30 AM
So, maybe I have the setup wrong. (after reading the FAQ'S)...?
If the form submits successfully.... I have the user to go a success.php page.
Do I need to be applying the valadation to THAT page? As I haven't been...
I just having been applying to the form page.
However, in form the action is blank ....but in WA insert it redirects to success.php....
Could this be causing the problem.
I am confident that I have made the code changes you suggested....
You have been very patient with me...And I appreciate it! :)

Ray Borduin
05-12-2009, 10:43 AM
The code should be on the form action page. Validation code should appear below the recordset code but above the insert code, and they should all be on the same page and not on the success page (blank action submits to the current page).