close ad
 
Important WebAssist Announcement
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 1/11/2021 1:59 pm by Ray Borduin | 865 views | 16 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

msbannister373603

Ray. Ok I can't get this working. This is the last thing holding me up. But I need to get this working. Let me know if I need to pay for your time. Thx Mike.

Here is my code: I followed the directions best I could understand


<?php require_once("../../webassist/form_validations/wavt_scripts_php.php"); ?>
<?php require_once('../../Connections/tsrbase.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_year = new WA_MySQLi_RS("WADAMenugrad_year",$tsrbase,0);
$WADAMenugrad_year->setQuery("SELECT playersID FROM players");
$WADAMenugrad_year->execute();?>
<?php
$gradYear = new WA_MySQLi_RS("gradYear",$tsrbase,0);
$gradYear->setQuery("SELECT * FROM grad");
$gradYear->execute();
?>

<?php
if ((isset($_POST["Insert"]) || isset($_POST["Insert_x"]))) {
$WAFV_Redirect = "playersInsert.php?NewPW2=Yes";
$_SESSION['WAVT_playersinsert_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(("tsrbase"),$tsrbase,$database_tsrbase,"players","playersID","none,none,NULL","0","player_name","',none,''","".((isset($_POST["player_name"]))?$_POST["player_name"]:"") ."",true,2);
$WAFV_Errors .= WAValidateUnique(("tsrbase"),$tsrbase,$database_tsrbase,"players","playersID","none,none,NULL","0","grad_year","',none,''","".((isset($_POST["grad_year"]))?$_POST["grad_year"]:"") ."",true,2);

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

<?php
if ((isset($_POST["Insert"]) || isset($_POST["Insert_x"]))) {
$WAFV_Redirect = "playersInsert.php?NewPW2=Yes";
$_SESSION['WAVT_playersinsert_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 .= WAValidateUnique(("tsrsports"),$tsrsports,$database_tsrsports,"players","playerID","none,none,NULL","0","grad_year","',none,''","".((isset($_POST["grad_year"]))?$_POST["grad_year"]:"") ."",true,2);

if ($WAFV_Errors != "") {
PostResult($WAFV_Redirect,$WAFV_Errors,"playersinsert");
}
}
?>
<?php
$players = new WA_MySQLi_RS("players",$tsrbase,1);
$players->setQuery("SELECT * FROM players WHERE player_name = ? AND grad_year = ?");
$players->bindParam("s", "".(isset($_GET['player_name'])?$_GET['player_name']:"") ."", "-1"); //colname
$players->bindParam("s", "".(isset($_GET['grad_year'])?$_GET['grad_year']:"") ."", "-1"); //colname
$players->execute();
?>
<?php echo($players->TotalRows) == 0; ?>
<?php
if (isset($_POST["Insert"]) || isset($_POST["Insert_x"])) {
$InsertQuery = new WA_MySQLi_Query($tsrbase);
$InsertQuery->Action = "insert";
$InsertQuery->Table = "players";
$InsertQuery->bindColumn("player_name", "s", "".((isset($_POST["player_name"]))?$_POST["player_name"]:"") ."", "WA_BLANK");
$InsertQuery->bindColumn("grad_year", "s", "".((isset($_POST["grad_year"]))?$_POST["grad_year"]:"") ."", "WA_BLANK");
$InsertQuery->saveInSession("WADA_Insert_players");
$InsertQuery->execute();
$InsertGoTo = "playersInsert.php?NewPW=Yes";
if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
$InsertQuery->redirect($InsertGoTo);
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Team Sports Registry Admin Panel</title>
<!-- Bootstrap -->
<link href="../../css/bootstrap-4.4.1.css" rel="stylesheet">
<link href="../../css/main.css" rel="stylesheet" type="text/css">
<link href="../../css/navLinks.css" rel="stylesheet" type="text/css">
<link href="../../css/table.css" rel="stylesheet" type="text/css">
<script src="../../webassist/progress_bar/jquery-blockui-formprocessing.js" type="text/javascript"></script>

<link href="../../webassist/forms/fd_basic_default.css" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="../../webassist/jq_validation/Bloom.css">

<script src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.min.js"></script>
<link href="../../webassist/forms/dataassist_button.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header" class="container">
<div class="row">
<div class="col-xl-5"><img src="../../vectors/tsrBlack.gif" alt="TSR Logo" class="img-fluid" id="tsrLogo"></div>
<div class="col-xl-6"></div>
</div>
</div>
<div id="navDirect" class="container">
<nav class="navbar navbar-expand-lg navbar-dark" style="background-color:#D0D0D0"> <a class="navbar-brand" href="#">Team Sports Registry</a>
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent1" aria-controls="navbarSupportedContent1" aria-expanded="false" aria-label="Toggle navigation"> Menu<span class="navbar-toggler-icon"></span> </button>
<div class="collapse navbar-collapse" id="navbarSupportedContent1">
<ul class="navbar-nav mr-auto col-xl-10">
<li class="nav-item active"> <a class="nav-link" href="javascript:history.go(-1)">Go Back<span class="sr-only">(current)</span></a> </li>
<li class="nav-item"> <a class="nav-link" href="../myPanel.php">Home</a> </li>
<li class="nav-item dropdown"> <a class="nav-link dropdown-toggle" href="#" id="navbarDropdown1" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false"> Control Panels </a>
<div class="dropdown-menu" aria-labelledby="navbarDropdown1"> <a class="dropdown-item" href="../myPanel.php">Home Control Panel</a>
<a class="dropdown-item" href="../myTeams.php">Rosters Control Panel</a><a class="dropdown-item" href="#">Public Control Panel</a> </div>
</li>
<li class="nav-item"> <a class="nav-link" href="file:///C|/wamp64/mike.html">Contact Us</a> </li>
<li class="nav-item"> <a class="nav-link" href="file:///C|/wamp64/mike.html">LogOut</a> </li>

</ul>
</div>
</nav>
</div>
<div id ="intro" class="container">
<div class="row">
<div class="col-xl-12"><div class="row">
<div id="namePage" class="col-xl-7">Players</div>
</div></div>
</div>
</div>
<?php if(isset($_GET['NewPW'])){ ?>
<div id="success" class="container">

<div class="row">
<div class="col-xl-12">
<div class="error" style="width:90%;">
<div class="alert alert-primary" role="alert">
The Player has been added to your Database!
</div></div>

</div></div>
</div><?php } ?>
<form class="Basic_Default" id="Insert_Basic_Default" name="Insert_Basic_Default" method="post" action="">
<div id="content" class="container">
<div class="col-xl-6">
<div class="input-group mb-3">
<div class="input-group-prepend">
<span class="input-group-text" id="basic-addon1">Player Name</span>
</div>
<input type="text" id="player_name" name="player_name" class="form-control" aria-label="Username" aria-describedby="basic-addon1"value="<?php echo((isset($_GET["invalid"])?ValidatedField("coachinsert","coach_name"):"")); ?>" tabindex="1" title="Please enter a value." required="true">
<?php
if (ValidatedField('playerinsert','playerinsert')) {
if ((strpos((",".ValidatedField("playerinsert","playerinsert").","), "," . "1" . ",") !== false || "1" == "")) {
if (!(false)) {
?><span class="serverInvalidState" id="player_name_ServerError">Please enter a value.</span><?php //WAFV_Conditional coach_insert.php coachinsert(1:)
}
}
}?>
</div>
</div>
<div class="col-xl-6"><select class="btn btn-secondary dropdown-toggle" name="grad_year" id="grad_year" rel="<?php echo((isset($_GET["invalid"])?ValidatedField("playersinsert","grad_year"):"")); ?>" tabindex="2" title="Please enter a value." required="true"><option value="" <?php if (!(strcmp("", (isset($_GET["invalid"])?ValidatedField("playersinsert","grad_year"):"")))) {echo "selected=\"selected\"";} ?>>Choose Grad Year</option>
<?php
while(!$gradYear->atEnd()) { //dyn select
?>
<option value="<?php echo($gradYear->getColumnVal("gradYear")); ?>"<?php if (!(strcmp($gradYear->getColumnVal("gradYear"), (isset($_GET["invalid"])?ValidatedField("playersinsert","grad_year"):"")))) {echo "selected=\"selected\"";} ?>><?php echo($gradYear->getColumnVal("gradYear")); ?></option>
<?php
$gradYear->moveNext();
} //dyn select
$gradYear->moveFirst();
?>
</select>
<?php
if (ValidatedField('playersinsert','playersinsert')) {
if ((strpos((",".ValidatedField("playersinsert","playersinsert").","), "," . "2" . ",") !== false || "2" == "")) {
if (!(false)) {
?><span class="serverInvalidState" id="grad_year_ServerError">Please enter a value.</span><?php //WAFV_Conditional players_insert.php playersinsert(2:)
}
}
}?></div><div id="button" class="row">
<div class="col-xl-12"><input class="btn btn-primary" type="submit" value="Insert" id="Insert" name="Insert" /></div>
</div>

</div>


</div><!--End of Container Tag-->
</form>
<div id="footer" class="container">
<div class="row">
<div class="col-xl-12">Content goes here | Placeholder Text | Placeholder Text | Placeholder Text</div>

</div>
</div>


<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
<script src="../../js/jquery-3.4.1.min.js"></script>

<!-- Include all compiled plugins (below), or include individual files as needed -->
<script src="../../js/popper.min.js"></script>
<script src="../../js/bootstrap-4.4.1.js"></script>
<div id="Insert_Basic_Default_ProgressMessageWrapper" class="blockUIOverlay" style="display:none;">
<script type="text/javascript">
WADFP_SetProgressToForm('Insert_Basic_Default', 'Insert_Basic_Default_ProgressMessageWrapper', WADFP_Theme_Options['BigSpin:Slate']);
</script>
<div id="Insert_Basic_Default_ProgressMessage" >
<p style="margin:10px; padding:5px;" ><img src="../../webassist/progress_bar/images/slate-largespin.gif" alt="" title="" style="vertical-align:middle;" />&nbsp;&nbsp;Please wait</p>
</div>
</div>


<script src="../../webassist/forms/wa_servervalidation.js" type="text/javascript"></script>
<script src="../../webassist/jq_validation/jquery.h5validate.js"></script>
<script>
var Insert_Basic_Default_Opts = {
focusout: true,
focusin: false,
change: false,
keyup: false,
popupClass: "Bloom",
pointedAt: "left",
fieldOffset: 10,
fieldMargin: 2,
position: "left",
direction: "left",
border: 1,
offset: 25,
closeText: "✖",
percentWidth: 100,
orientation: "bottom"
};
function Insert_Basic_Default_Validate() {
$("#Insert_Basic_Default").h5Validate(Insert_Basic_Default_Opts);
}
$(document).ready(function () {
Insert_Basic_Default_Validate()
ConvertServerErrors(Insert_Basic_Default_Opts);
});
</script>
</body>
</html>

Sign in to reply to this post

Ray BorduinWebAssist

Please attach the page when posting questions instead of using copy/paste so I can open and view the code in Dreamweaver.

It looks like you have two Server Validations server behaviors on the page, and you have blank lines in your code.

Delete the second one, and delete the blank lines.

Then it looks like you have unique value server validation... That won't work, since you are comparing the values of two columns. Instead copy/paste the players recordset above the Server Validation code and add number validation to validate the value of:

<?php echo($players->TotalRows); ?>

Set the max value to zero (no matched rows).

After doing that, if it still doesn't work, attach the page to a reply and I'll take another look.

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

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