close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

Check duplicate entry if exist for two field during insert

Thread began 7/18/2021 6:10 pm by Rokon | Last modified 7/21/2021 9:32 pm by Ray Borduin | 466 views | 7 replies |

Rokon

Check duplicate entry if exist for two field during insert

Hello

I have a data insert page where before inserting the data to the table need to cross check of two fields data whether it is existing in the table or not, (Like UserID & ItemID) if not exist then it should insert othewise it will report an error that entry is duplicating. Could not figure it out, pls help.

Sign in to reply to this post

Ray BorduinWebAssist

What do you want to do if they do exist? Throw an error? You could probably add a recordset to filter on the two columns you want to check, then add server validation to validate that the recordset doesn't have any results. Then the server validation could be used to show an error message if the duplicate was found.

If you wanted to ignore or update instead of insert when duplicates were found, then there are other options for that as well.

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

Rokon

I think I am not smart enough to catch you on this situation and need little more guide for me. By reading some other post (http://www.webassist.com/forums/posts.php?t=19462) i created like this but unsuccessful.

php:
<?php require_once('../../../webassist/framework/framework.php'); ?>

<?php 
require_once('../../../webassist/framework/library.php'); ?>
<?php 
require_once("../../../webassist/form_validations/wavt_scripts_php.php"); ?>
<?php 
require_once("../../../webassist/form_validations/wavt_validatedform_php.php"); ?>
<?php 
require_once('../../../Connections/hadithbd.php'); ?>
<?php 
require_once('../../../webassist/mysqli/queryobj.php'); ?>
<?php 
require_once('../../../webassist/mysqli/rsobj.php'); ?>
<?php
$hadithEcho 
= new WA_MySQLi_RS("hadithEcho",$hadithbd,1);
$hadithEcho->setQuery("SELECT hadithmain.HadithID, hadithmain.BanglaHadith FROM hadithmain WHERE hadithmain.HadithID = ?");
$hadithEcho->bindParam("i""".(isset($_GET['i'])?$_GET['i']:"")  ."""-1"); //WAQB_Param1
$hadithEcho->execute();?>
<?php
$duplicatecheck 
= new WA_MySQLi_RS("duplicatecheck",$hadithbd,1);
$duplicatecheck->setQuery("SELECT activity_tag.* FROM activity_tag WHERE activity_tag.userid = ? AND activity_tag.TagGroup = 2 AND activity_tag.tagName = ?");
$duplicatecheck->bindParam("i""".(isset($_SESSION['UserID'])?$_SESSION['UserID']:"")  ."""-1"); //WAQB_Param1
$duplicatecheck->bindParam("s""".(isset($_POST['tagname'])?$_POST['tagname']:"")  ."""-1"); //WAQB_Param2
$duplicatecheck->execute();
?>
<?php 
if (isset($_POST["newTagName"]) || isset($_POST["newTagName_x"]))  {
  
$WAFV_Redirect "";
  
$_SESSION['WAVT_index_454_Errors'] = "";
  if (
$WAFV_Redirect == "")  {
    
$WAFV_Redirect $_SERVER["PHP_SELF"];
  }
  
$WAFV_Errors "";
  
$WAFV_Errors .= WAValidateNM($totalRows_duplicatecheck "",-1,0,"",",.",true,2);

  if (
$WAFV_Errors != "")  {
    
PostResult($WAFV_Redirect,$WAFV_Errors,"index_454");
  }
}
?>
<?php
if (isset($_POST["addTag"]) || isset($_POST["addTag_x"])) {
  
$InsertQuery = new WA_MySQLi_Query($hadithbd);
  
$InsertQuery->Action "insert";
  
$InsertQuery->Table "activity_usertag";
  
$InsertQuery->bindColumn("tagID""i""".((isset($_POST["tagid"]))?$_POST["tagid"]:"")  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("userID""i""".((isset($_POST["userid"]))?$_POST["userid"]:"")  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("itemID""i""".((isset($_POST["itemID"]))?$_POST["itemID"]:"")  ."""WA_DEFAULT");
  
$InsertQuery->saveInSession("");
  
$InsertQuery->execute();
  
$InsertGoTo "../../done.php";
  if (
function_exists("rel2abs")) $InsertGoTo $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
  
$InsertQuery->redirect($InsertGoTo);
}
?>
<?php
if (isset($_POST["newTagName"]) || isset($_POST["newTagName_x"])) {
  
$InsertQuery = new WA_MySQLi_Query($hadithbd);
  
$InsertQuery->Action "insert";
  
$InsertQuery->Table "activity_tag";
  
$InsertQuery->bindColumn("TagGroup""i""".((isset($_POST["tagGroup"]))?$_POST["tagGroup"]:"")  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("userid""i""".((isset($_POST["userID"]))?$_POST["userID"]:"")  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("tagName""s""".((isset($_POST["tagname"]))?$_POST["tagname"]:"")  ."""WA_DEFAULT");
  
$InsertQuery->saveInSession("");
  
$InsertQuery->execute();
  
$InsertGoTo "../../done.php";
  if (
function_exists("rel2abs")) $InsertGoTo $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
  
$InsertQuery->redirect($InsertGoTo);
}
?>
<?php
if("" == ""){
    
$WA_hadithbd_template_1626710882918_Content_Empty "";
    
$WA_hadithbd_template_1626710882918_Content = new WA_Include(__FILE__); 
    
$WA_hadithbd_template_1626710882918_Template = new WA_Include("../../../Templates{$WA_hadithbd_template_1626710882918_Content_Empty}/hadithbd-template.dwt.php");
    require(
$WA_hadithbd_template_1626710882918_Template->BaseName);
    
$WA_hadithbd_template_1626710882918_Template->Initialize(true);
}
?><?php
if("" === ""){
    
$WA_taglist_1626711423766 = new WA_Include("taglist.php");
    require(
$WA_taglist_1626711423766->BaseName);
    
$WA_taglist_1626711423766->Initialize(true);
}
?><?php
if("" === ""){
    
$WA_hadithlist_1626736156793 = new WA_Include("hadithlist.php");
    require(
$WA_hadithlist_1626736156793->BaseName);
    
$WA_hadithlist_1626736156793->Initialize(true);
}
?>
<!doctype html>
<html lang="bn"><!-- InstanceBegin template="/Templates/Themes/hadithbd-template_fw_theme.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- InstanceBeginEditable name="doctitle" -->
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<script type="text/javascript"  src="../../../webassist/framework/javascript/ajax.js"></script>
<script type="text/javascript">
function framework_load_plugin_url(plugin,form,div,framework_path,on_success_start,on_success_end)  {
    document.MM_returnValue = false;
    framework_ajax_plugin(form,plugin,div,framework_path,false,on_success_start,on_success_end); 
    return true;    
}
</script>
<!-- InstanceEndEditable -->
</head>
<body>
<!-- InstanceBeginEditable name="Main-body-area" -->
    <main>
  <div class="container  mt-4 mb-5">
    <div class="card bg-light shadow">
      <div class="card-header shadow d-none d-sm-block titleMain">Header</div>
      <div class="card-header shadow d-block d-sm-none titleChild">Header</div>
      <div class="card-body">
        <h5 class="card-title"><?php echo($user->getColumnVal("UserFullName")); ?></h5>
          
          <div class="row">
              <div class="col-md-6">
        <div class="card-text">
          
          <form  action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" id="addNewTag">
            <input name="userid" type="hidden" id="userid" form="addNewTag" required value="<?php echo (isset($_GET['u'])?$_GET['u']:""); ?>">
        
        
        <input name="itemID" type="hidden" id="itemID" form="addNewTag" required value="<?php echo (isset($_GET['i'])?$_GET['i']:""); ?>">
            <div id="tag-list"><?php echo((isset($WA_taglist_1626711423766))?$WA_taglist_1626711423766->Body:""?>
              </div>
                         
              
              <button type="submit" name="addTag" class="btn btn-success">Add Tag</button>
              
              <button name="reload" class="btn btn-warning" onClick="framework_load_plugin_url('plugins/taglist.php',document.getElementById('addNewTag'),'tag-list','../../../','');return document.MM_returnValue">Reload</button>
              
          </form>
            
            <p>
              <?php
  
if ("".($hadithEcho->getColumnVal("HadithID"))  ."" != "") {  // WebAssist Show If
?>
                <?php

$text 
html_entity_decode($hadithEcho->getColumnVal("BanglaHadith"));
echo 
substr($text01500).".......";

?>
                <?php
  
// ("".($hadithEcho->getColumnVal("HadithID"))  ."" != "")
?>
            </p>
          
          <!-- Button trigger modal -->
<button type="button" class="btn btn-primary" data-toggle="modal" data-target="#exampleModalCenter">
  Launch demo modal
</button>

<!-- Modal -->
<div class="modal fade" id="exampleModalCenter" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle" aria-hidden="true">
  <div class="modal-dialog modal-dialog-centered" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="exampleModalLongTitle">Modal title</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>
      <div class="modal-body">
      <form  action="<?php echo htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" enctype="multipart/form-data" id="newTagName">
      
        <div class="form-group  mt-3">
    
    <input name="tagname" type="text" required="required" class="form-control" id="tagname" form="newTagName" placeholder="Tag Name">
  </div>
       <input name="userID" type="hidden" id="userID" form="newTagName" required value="<?php echo (isset($_GET['u'])?$_GET['u']:""); ?>">
        
        <input name="tagGroup" type="hidden" id="tagGroup" form="newTagName" required value="2">
  
           <div class="form-group">
    <button type="submit" name="newTagName" class="btn btn-success">ট্যাগ তৈরি করুন</button>
  </div>
      
      
      </form>
      </div>
      <div class="modal-footer">
        <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary">Save changes</button>
      </div>
    </div>
  </div>
</div>
            
            
        </div>
     </div>
        <div class="col-md-6"><?php echo((isset($WA_hadithlist_1626736156793))?$WA_hadithlist_1626736156793->Body:""?>
              
              
              
              </div>
        </div>
          
        </div>
    </div>
  </div>
</main>
<!-- InstanceEndEditable -->
</body>
<!-- InstanceEnd --></html>
<?php
if(isset($WA_hadithbd_template_1626710882918_Template)){
    
$WA_hadithbd_template_1626710882918_Content->Initialize();
    
$WA_hadithbd_template_1626710882918_Template->ReplaceTemplateRegions($WA_hadithbd_template_1626710882918_Content);
    print(
$WA_hadithbd_template_1626710882918_Template->Content);
}
?>
Sign in to reply to this post

Ray BorduinWebAssist

Please attach the .php page so I can open it in Dreamweaver instead of using copy/paste in the future.

I see your recordset uses $_SESSION['UserID'] and your insert uses $_POST["userid"]

That may be the issue.

Also you are validating the value of:
$totalRows_duplicatecheck

but with MySQLi the syntax should be:
$duplicatecheck->TotalRows

I think everything else looks correct.

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

Rokon

I am attaching the file herewith, Thanks.

Sign in to reply to this post

Ray BorduinWebAssist

I see your recordset uses $_SESSION['UserID'] and your insert uses $_POST["userid"]

That may be the issue.

Also you are validating the value of:
$totalRows_duplicatecheck

but with MySQLi the syntax should be:
$duplicatecheck->TotalRows

I think everything else looks correct.

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

Rokon

The problem was on $totalRows_duplicatecheck and other part didin't create any problem. Thanks ray, but I think for the duplicate check should have a easy method of wizard, because this is a common issue in everyday life.

Sign in to reply to this post

Ray BorduinWebAssist

It does have an easy option for a single column duplicate check, just not multiple. It is actually fairly uncommon. Search this forum for how many people have asked for it over the past 20 years.

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

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