close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Unique ID - 2 fields must match to allow insert

Thread began 11/18/2020 5:12 am by msbannister373603 | Last modified 11/18/2020 11:00 am by Ray Borduin | 21 views | 7 replies |

msbannister373603

Unique ID - 2 fields must match to allow insert

I'm using the unique ID to prevent multiple inserts into dabase. I have a input for name, then a select menu for year. How can I amend the code so that the input and menu match before the insert is denied. For example, I have Mike-1998 in the database. How can I prevent Mike-1998 from being inserted, yet allow Mike-2012. Thx

Sign in to reply to this post

Ray BorduinWebAssist

You could use a Recordset above the Server Validation code to check to see if there is a matching entry by filtering by both values. Then validate the value of:
<?php echo($Recordset1->TotalRows); ?> with number validation with a maximum of 0.

Sign in to reply to this post
Did this help? Tips are appreciated...

anonymous

Above this code? Not sure what you mean?

<?php
if (ValidatedField('players3insert','players3insert')) {
if ((strpos((",".ValidatedField("players3insert","players3insert").","), "," . "1" . ",") !== false || "1" == "") || (strpos((",".ValidatedField("players3insert","players3insert").","), "," . "2" . ",") !== false || "2" == "")) {
if (!(false)) {
?><span class="serverInvalidState" id="player_name_ServerError">Please enter a value.</span><?php //WAFV_Conditional players3_insert.php players3insert(1,2:)
}
}
}?>

Sign in to reply to this post

Ray BorduinWebAssist

No... at the very top of the page... First code. That way you can reference it in the Server Validation code below.

The code you pasted is the Validation Show If code. Click on Server Validations in the Server Behaviors panel and it will highlight the code your recordset has to be above.

Sign in to reply to this post
Did this help? Tips are appreciated...

anonymous

Here's what I have. not working. The insert works but it's not stopping the duplicate

<?php
$WADAMenugrad = new WA_MySQLi_RS("WADAMenugrad",$tsrsports,0);
$WADAMenugrad->setQuery("SELECT season, seasonID FROM season ORDER BY season ASC");
$WADAMenugrad->execute();
?>
<?php
if (isset($_POST["Insert"]) || isset($_POST["Insert_x"])) {
$InsertQuery = new WA_MySQLi_Query($tsrsports);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "players";
$InsertQuery->bindColumn("player_name", "s", "".((isset($_POST["player_name"]))?$_POST["player_name"]:"") ."", "WA_BLANK");
$InsertQuery->bindColumn("grad", "s", "".((isset($_POST["grad"]))?$_POST["grad"]:"") ."", "WA_BLANK");
$InsertQuery->saveInSession("WADA_Insert_players");
$InsertQuery->execute();
$InsertGoTo = "players3_insert.php?playerID=[Insert_ID]";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
?>
<?php
if ((isset($_POST["Insert"]) || isset($_POST["Insert_x"]))) {
$WAFV_Redirect = "".($_SERVER["REQUEST_URI"]) ."?invalid=true";
$_SESSION['WAVT_players3insert_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateRQ((isset($_POST["player_name"])?$_POST["player_name"]:"") . "",true,1);
$WAFV_Errors .= WAValidateUnique(("tsrsports"),$tsrsports,$database_tsrsports,"players","playerID","none,none,NULL","0","player_name","',none,''","".((isset($_POST["player_name"]))?$_POST["player_name"]:"") ."",true,2);
$WAFV_Errors .= WAValidateRQ((isset($_POST["grad"])?$_POST["grad"]:"") . "",true,3);

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

Sign in to reply to this post

Ray BorduinWebAssist

1) The insert code has to be after the server validation code.

2) The recordset has to be added that is filtered by the two columns you want to make sure comprise a unique entry.

3) You have to add a number validation for the added recordset TotalRows to check that it is empty and doesn't have an existing record.

Sign in to reply to this post
Did this help? Tips are appreciated...

anonymous

I'm not understanding this:

ou could use a Recordset above the Server Validation code to check to see if there is a matching entry by filtering by both values. Then validate the value of:
<?php echo($Recordset1->TotalRows); ?> with number validation with a maximum of 0.


I did put the recordset in:

<?php require_once('../../Connections/tsrsports.php'); ?>
<?php require_once("../../webassist/form_validations/wavt_scripts_php.php"); ?>
<?php require_once("../../webassist/form_validations/wavt_validatedform_php.php"); ?>
<?php require_once('../../webassist/mysqli/queryobj.php'); ?>
<?php require_once('../../webassist/mysqli/rsobj.php'); ?>
<?php
$WADAMenugrad = new WA_MySQLi_RS("WADAMenugrad",$tsrsports,0);
$WADAMenugrad->setQuery("SELECT season, seasonID FROM season ORDER BY season ASC");
$WADAMenugrad->execute();?>
<?php
$playersFilter = new WA_MySQLi_RS("playersFilter",$tsrsports,1);
$playersFilter->setQuery("SELECT * FROM players WHERE player_name = ?");
$playersFilter->bindParam("s", "".(isset($_GET['grad'])?$_GET['grad']:"") ."", "-1"); //colname
$playersFilter->execute();
?>

<?php
if ((isset($_POST["Insert"]) || isset($_POST["Insert_x"]))) {
$WAFV_Redirect = "".($_SERVER["REQUEST_URI"]) ."?invalid=true";
$_SESSION['WAVT_players3insert_Errors'] = "";
if ($WAFV_Redirect == "") {
$WAFV_Redirect = $_SERVER["PHP_SELF"];
}
$WAFV_Errors = "";
$WAFV_Errors .= WAValidateRQ((isset($_POST["player_name"])?$_POST["player_name"]:"") . "",true,1);
$WAFV_Errors .= WAValidateUnique(("tsrsports"),$tsrsports,$database_tsrsports,"players","playerID","none,none,NULL","0","player_name","',none,''","".((isset($_POST["player_name"]))?$_POST["player_name"]:"") ."",true,2);
$WAFV_Errors .= WAValidateRQ((isset($_POST["grad"])?$_POST["grad"]:"") . "",true,3);

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

<?php
if (isset($_POST["Insert"]) || isset($_POST["Insert_x"])) {
$InsertQuery = new WA_MySQLi_Query($tsrsports);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "players";
$InsertQuery->bindColumn("player_name", "s", "".((isset($_POST["player_name"]))?$_POST["player_name"]:"") ."", "WA_BLANK");
$InsertQuery->bindColumn("grad", "s", "".((isset($_POST["grad"]))?$_POST["grad"]:"") ."", "WA_BLANK");
$InsertQuery->saveInSession("WADA_Insert_players");
$InsertQuery->execute();
$InsertGoTo = "players3_insert.php?playerID=[Insert_ID]";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
?>

Sign in to reply to this post

anonymous

Thx. I got it working

Mike

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...