473,395 Members | 1,974 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Why am I getting duplicate entries?

Jon Wenzel
This is blowing my mind. I've got a system where sales reps can write notes on contacts in the DB. The issue is, I'm getting duplicate notes, but they're happening at different times. Each note is time stamped, and the duplicates are happening sometimes 3 or 4 hours later, after the user is no longer on the site. I'm totally stumped with this. So here are the 2 pages that are used in the site.

The first one is the index page, every page gets loaded within it.
Expand|Select|Wrap|Line Numbers
  1.  
  2. <?
  3. session_start();
  4. include('includes/db.inc.php');
  5.  
  6.  
  7. if (isset($_SESSION['mycontent']))
  8. {
  9.     $username = $_SESSION['mycontent'];
  10.     $query = "SELECT * FROM users WHERE username = \"$username\"";
  11.     $result = mysql_query($query) or die('Sorry, could not get cookie at this time ');    
  12.     $row = mysql_fetch_array($result, MYSQL_ASSOC);
  13.     $username = $row['username'];
  14.     $fname = $row['fname'];
  15.     $lname = $row['lname'];
  16.     $admin = $row['admin'];
  17.     $userid = $row['userid'];
  18.     $userID = $userid;
  19.     $fullName = "$fname $lname";
  20.         } else { die ( "<h2>You must be logged in to view this content. </h2><br>
  21.  
  22.                  <form action=\"validate.php\" method=\"post\" >
  23. User Name:
  24. <input name=\"username\" type=\"text\" class=\"search_box\" size=\"20\" id=\"username\">
  25. Password:<input name=\"password\" type=\"password\" class=\"search_box\" size=\"20\"> 
  26. <input type=\"submit\" class=\"search_box\" value=\"Login\">
  27. </form>
  28.  
  29.  
  30.  
  31.  
  32.  
  33.                  \n");
  34. }
  35.  
  36. ?>
  37.  
  38. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  39. <html xmlns="http://www.w3.org/1999/xhtml">
  40. <head>
  41. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  42. <title></title>
  43. <link href="cc.css" rel="stylesheet" type="text/css" />
  44.  
  45. <script language = "javascript" type = "text/javascript">
  46.     <!-- Start hiding JavaScript statements
  47.  
  48.       var Request = false; 
  49.       if (window.XMLHttpRequest) {
  50.         Request = new XMLHttpRequest();
  51.       } else if (window.ActiveXObject) {
  52.         Request = new ActiveXObject("Microsoft.XMLHTTP");
  53.       }
  54.  
  55.       function checkingAlerts() {
  56.     checkAlerts()
  57.     setInterval("checkAlerts()",15000);
  58.  
  59.     }
  60.  
  61.  
  62.  
  63.  
  64.       function checkAlerts() {
  65.  
  66.         var url = "alertsCheck.php?userid=" + <? echo $userID; ?>;
  67.  
  68.         if(Request) {
  69.           var target2 = document.getElementById('alerts'); 
  70.           Request.open("GET", url, true); 
  71.           Request.onreadystatechange = function() { 
  72.             if (Request.readyState == 4 && Request.status == 200) { 
  73.                 target2.innerHTML = Request.responseText; 
  74.  
  75.             } 
  76.           } 
  77.           Request.send(null); 
  78.         }
  79. }
  80.  
  81.  
  82.  
  83.  
  84. function startup(){
  85. checkingAlerts();
  86. checkingStatus()
  87. }
  88. </script>
  89.  
  90.  
  91.  
  92.  
  93.  
  94. </head>
  95. <body onLoad="startup()">
  96.  
  97. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  98.   <tr>
  99.     <td align="right" class="usermenu" bgcolor="#2E3E57"><? include('userMenu.php'); ?></td>
  100.   </tr>
  101.   <tr>
  102.     <td align="left" class="menu_content"><h1>myCommand Center v0.0.5</h1></td>
  103.   </tr>
  104.   <tr>
  105.     <td><ol>
  106.       <li><a href="index.php?content=contacts/view-all.php">Contacts</a>
  107.       </li>
  108.       <li><a href="index.php?content=clients/view-all.php">Clients</a></li>
  109.       <li><a href="#">Schedule</a></li>
  110.       <li><a href="#">Resources</a></li>
  111.       <li><a href="#">Reports</a></li>
  112.       <li><a href="#">Compensation &amp; Incentives</a></li>
  113.     </ol>    </td>
  114.   </tr>
  115.   <tr>
  116.     <td><?
  117. $contactID = $_GET['contactID'];
  118.  
  119. ?><script language = "javascript" type = "text/javascript">
  120.     <!-- Start hiding JavaScript statements
  121.  
  122.       var Request = false; 
  123.       if (window.XMLHttpRequest) {
  124.         Request = new XMLHttpRequest();
  125.       } else if (window.ActiveXObject) {
  126.         Request = new ActiveXObject("Microsoft.XMLHTTP");
  127.       }
  128.  
  129.  
  130.  
  131.  
  132.       function checkStatus(target) {
  133.                   var userid = "<? echo $userid; ?>";
  134.  
  135.         var url = "status.php?contactID=" + <? echo $contactID; ?> + "&userid=" + userid;
  136.  
  137.         if(Request) {
  138.           var target2 = document.getElementById(target); 
  139.           Request.open("GET", url, true); 
  140.           Request.onreadystatechange = function() { 
  141.             if (Request.readyState == 4 && Request.status == 200) { 
  142.                 target2.innerHTML = Request.responseText; 
  143.  
  144.             } 
  145.           } 
  146.           Request.send(null); 
  147.         }
  148. }
  149.  
  150.     function checkingStatus() {
  151.     checkStatus('status')
  152.     setInterval("checkStatus('status')",15000);
  153.  
  154.     }
  155.  
  156.     function newNote(belongsTo) {
  157.         var note = document.getElementById('note').value;
  158.         var rep = "<? echo $fullName; ?>"
  159.         var repID = "<? echo $userID; ?>"
  160.         var belongsTo = belongsTo
  161.         var url = "addNote.php?contactID=" + <? echo $contactID; ?>+ "&rep=" + rep + "&repID=" + repID + "&belongsTo=" + belongsTo + "&note=" + note;
  162.  
  163.         if(Request) {
  164.           var target2 = document.getElementById('notesBox'); 
  165.           Request.open("GET", url, true); 
  166.           Request.onreadystatechange = function() { 
  167.             if (Request.readyState == 4 && Request.status == 200) { 
  168.                 target2.innerHTML = Request.responseText; 
  169.  
  170.             } 
  171.           } 
  172.           Request.send(null); 
  173.         }
  174.  
  175.     }
  176.  
  177.  
  178.  
  179.  
  180.  
  181.     function claimContact() {
  182.         var rep = "<? echo $userid; ?>"
  183.         var url = "claimContact.php?contactID=" + <? echo $contactID; ?>+ "&rep=" + rep;
  184.  
  185.         if(Request) {
  186.           var target2 = document.getElementById('status'); 
  187.           Request.open("GET", url, true); 
  188.           Request.onreadystatechange = function() { 
  189.             if (Request.readyState == 4 && Request.status == 200) { 
  190.                 target2.innerHTML = Request.responseText;
  191.                 checkStatus('status');
  192.             } 
  193.           } 
  194.           Request.send(null); 
  195.         }
  196.  
  197.     }
  198.     function makeClient() {
  199.  
  200.         var url = "makeClient.php?contactID=" + <? echo $contactID; ?>;
  201.  
  202.         if(Request) {
  203.           var target2 = document.getElementById('status'); 
  204.           Request.open("GET", url, true); 
  205.           Request.onreadystatechange = function() { 
  206.             if (Request.readyState == 4 && Request.status == 200) { 
  207.                 target2.innerHTML = Request.responseText;
  208.                 checkStatus('status');
  209.             } 
  210.           } 
  211.           Request.send(null); 
  212.         }
  213.  
  214.     }
  215.     function makeContact() {
  216.  
  217.         var url = "makeContact.php?contactID=" + <? echo $contactID; ?>;
  218.  
  219.         if(Request) {
  220.           var target2 = document.getElementById('status'); 
  221.           Request.open("GET", url, true); 
  222.           Request.onreadystatechange = function() { 
  223.             if (Request.readyState == 4 && Request.status == 200) { 
  224.                 target2.innerHTML = Request.responseText;
  225.                 checkStatus('status');
  226.             } 
  227.           } 
  228.           Request.send(null); 
  229.         }
  230.  
  231.     }
  232.  
  233.     function unclaimContact() {
  234.         var rep = "<? echo $userid; ?>"
  235.         var url = "unclaimContact.php?contactID=" + <? echo $contactID; ?>+ "&rep=" + rep;
  236.  
  237.         if(Request) {
  238.           var target2 = document.getElementById('status'); 
  239.           Request.open("GET", url, true); 
  240.           Request.onreadystatechange = function() { 
  241.             if (Request.readyState == 4 && Request.status == 200) { 
  242.                 target2.innerHTML = Request.responseText;
  243.                 checkStatus('status');
  244.             } 
  245.           } 
  246.           Request.send(null); 
  247.         }
  248.  
  249.     }
  250.  
  251.  
  252.     function deleteNote(noteID, belongsTo) {
  253.         var belongsTo = belongsTo
  254.  
  255.         var url = "deleteNote.php?contactID=" + <? echo $contactID; ?> + "&belongsTo=" + belongsTo + "&noteID=" + noteID;
  256.  
  257.         if(Request) {
  258.           var target2 = document.getElementById('notesBox'); 
  259.           Request.open("GET", url, true); 
  260.           Request.onreadystatechange = function() { 
  261.             if (Request.readyState == 4 && Request.status == 200) { 
  262.                 target2.innerHTML = Request.responseText;
  263.  
  264.             } 
  265.           } 
  266.           Request.send(null); 
  267.         }
  268.  
  269.     }
  270.  
  271.  
  272.  
  273.     // End hiding JavaScript statements -->
  274.  
  275.     </script>
  276.  
  277.     <link href="../cc.css" rel="stylesheet" type="text/css">
  278.  
  279.   <?
  280.  
  281.           $query = "SELECT * from contacts WHERE contactID = $contactID";
  282.         $result = mysql_query($query) or die('Sorry, could not get entires at this time ');
  283.  
  284.  
  285.  
  286. echo "<div class=\"subMenu\" align=\"left\">";
  287. echo "<a href=\"index.php?content=contacts/view-all.php\">all contacts</a> | <a href=\"index.php?content=contacts/view-mine.php\">my contacts</a> | <a href=\"index.php?content=contacts/view-claimed.php\">all claimed</a> | <a href=\"index.php?content=contacts/view-unclaimed.php\">unclaimed</a> | <a href=\"index.php?content=contacts/view-blacklisted.php\">blacklisted</a>";
  288. echo "</div>";
  289.  
  290.  
  291. echo "<div id=\"borderPad\" align=\"left\">";
  292. $row=mysql_fetch_array($result, MYSQL_ASSOC);
  293.  
  294.        $contactID = $row['contactID'];
  295.        $repID = $row['repID'];
  296.        $phone= $row['phone'];
  297.        $busName = $row['busName'];
  298.        $fname = $row['fname'];
  299.        $lname = $row['lname'];
  300.        $status = $row['status'];
  301.        $email = $row['email'];
  302.        $address = $row['address'];
  303.        $city = $row['city'];
  304.           $state = $row['state'];
  305.           $title = $row['title'];
  306.           $zip = $row['zip'];
  307.           $website = $row['website'];
  308.           $industry = $row['industry'];
  309.         $belongsTo = $repID;
  310. // Contact Status
  311. if ($status == 0){
  312.     $statusMsg = "Has not been contacted (<span onClick=\"claimContact()\" style=\"cursor:pointer;\">claim</span>)";
  313. } elseif ($status == 1){
  314.     $statusMsg = "Contact is not interested.  <u>DO NOT CONTACT</u>";
  315. } elseif ($status == 2){
  316.     $statusMsg = "Contact has been assigned to another rep";
  317. } else {
  318.     $statusMsg = "Contact is a client";
  319. }
  320.  
  321. if ($title){
  322.     $ifTitle = $title; 
  323. } else {
  324.     $ifTitle = '';
  325. }
  326.  
  327. $fullAddress = 0;
  328.  
  329. if (!$address){
  330.     $fullAddress = 1;
  331. }
  332.  
  333.  
  334. if (!$city){
  335.     $fullAddress = 1;
  336. }
  337.  
  338.  
  339. if (!$state){
  340.     $fullAddress = 1;
  341. }
  342.  
  343.  
  344. if (!$zip){
  345.     $fullAddress = 1;
  346. }
  347.  
  348. $proAddress = str_replace (' ', '+', $address);
  349. $proCity = str_replace (' ', '+', $city);
  350.  
  351.  
  352.  
  353. echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
  354. echo "<tr>";
  355. echo "<td>";
  356.  
  357. // Left column
  358. echo "<h2>$busName</h2>";
  359. echo "Industry: $industry<br><br><strong>Contact Info</strong><br>Contact: $fname $lname $ifTitle<br>Phone: $phone <br> Email: $email (compose email)<br>Website: $website<br><br>";
  360. echo "<strong>Address</strong><br>$address <br>$city, $state $zip"; 
  361.  
  362. if ($fullAddress == 0) {
  363. echo "(<a href=\"http://maps.google.com/maps?f=q&source=s_q&hl=en&geocode=&q=$proAddress+$proCity+$state+$zip\" target=\"blank\">get directions</a>)";
  364. }
  365.  
  366.  
  367. echo "</td>";
  368.  
  369. // Right Column
  370. echo "<td valign=\"top\" align=\"right\">"; 
  371.  
  372. ?><div id="status"></div>
  373. <? 
  374.  
  375.  
  376. echo "</td>";
  377. echo "</tr>";
  378. echo "</table>";
  379. echo "</div>";
  380.  
  381.  
  382.  
  383.  
  384. ?>
  385. <div id="notesBox">
  386. <?       
  387.  
  388.           $query2 = "SELECT noteID, contactID, salesRep, DATE_FORMAT( noteDate, '%c/%e/%Y @ %l:%i %p'), note FROM notes WHERE contactID = $contactID ORDER BY noteDate ASC";
  389.         $result2 = mysql_query($query2) or die('Sorry, could not get entires at this time ');
  390.         while($row2=mysql_fetch_array($result2, MYSQL_ASSOC))
  391.    {
  392.        $noteID = $row2['noteID'];
  393.        $contactID = $row2['contactID'];
  394.        $salesRep = $row2['salesRep'];
  395.        $noteDate = $row2["DATE_FORMAT( noteDate, '%c/%e/%Y @ %l:%i %p')"];
  396.        $note = $row2['note'];
  397. echo "<div class=\"notes\" align=\"left\">";
  398. echo "$noteDate - $salesRep <span onClick=\"deleteNote('$noteID','$belongsTo')\" style=\"cursor:pointer;\">[delete comment]</span><br>$note";
  399. echo "</div>";
  400. }
  401. echo "<span class=\"cursor\" onClick=\"document.getElementById('noteForm').style.display=''\">add note</span>";
  402. echo "<div id=\"noteForm\" style=\"display:none;\">
  403. <label>
  404.   <textarea name=\"note\" cols=\"65\" rows=\"8\" class=\"notes\" id=\"note\"></textarea>
  405. </label>
  406.     <label><br>
  407.     </label>
  408.     <label>
  409.       <input type=\"button\" name=\"button2\" id=\"button2\" value=\"Nevermind\" onClick=\"document.getElementById('noteForm').style.display='none'\">
  410.     </label>
  411.   <input type=\"button\" name=\"button\" id=\"button\" value=\"Submit\" onClick=\"newNote('$belongsTo')\">";
  412.  
  413. ?>
  414. </div>
  415.  
  416. </div>
  417.     </td>
  418.   </tr>
  419.   <tr>
  420.     <td><? include('../includes/footer.inc.php'); ?></td>
  421.   </tr>
  422. </table>
  423. </body>
  424. </html>
  425.  
Then is the PHP script that adds the comment, then adds an alert to all users who have commented on that contact...

Expand|Select|Wrap|Line Numbers
  1. <?
  2. $con = // server connection info ;
  3.  
  4. $contactID = $_GET['contactID'];
  5. $newNote = $_GET['note'];
  6. $salesRep = $_GET['rep'];
  7. $repID = $_GET['repID'];
  8. $belongsTo = $_GET['belongsTo'];
  9. // Add new comment
  10. $query = "INSERT INTO notes (`noteID`,`contactID`,`salesRep`,`noteDate`,`note`, `salesRepID`)VALUES (NULL ,  '$contactID',  '$salesRep', NOW( ) ,  '$newNote', '$repID')";
  11. $result = mysql_query($query) or die('Our note system appears to be having issues.  One of the Matts probably broke it. Error 1');
  12.  
  13.  
  14. $query1 = "INSERT INTO alertsNote (`alertID` ,`contactID` ,`toto` ,`from`) VALUES (NULL ,  '$contactID',  '$belongsTo',  '$salesRep')";
  15. $result1 = mysql_query($query1) or die('Our note system appears to be having issues.  One of the Matts probably broke it.');
  16.  
  17. // All passed, show the new comments.
  18.  
  19.  
  20.           $query2 = "SELECT noteID, contactID, salesRep, DATE_FORMAT( noteDate, '%c/%e/%Y @ %l:%i %p'), note FROM notes WHERE contactID = $contactID ORDER BY noteDate ASC";
  21.         $result2 = mysql_query($query2) or die('Sorry, could not get entires at this time ');
  22.         while($row2=mysql_fetch_array($result2, MYSQL_ASSOC))
  23.    {
  24.        $noteID = $row2['noteID'];
  25.        $contactID = $row2['contactID'];
  26.        $salesRep = $row2['salesRep'];
  27.        $noteDate = $row2["DATE_FORMAT( noteDate, '%c/%e/%Y @ %l:%i %p')"];
  28.        $note = $row2['note'];
  29. ?>
  30. <?       
  31. echo "<div class=\"notes\" align=\"left\">";
  32. echo "$noteDate - $salesRep <span onClick=\"deleteNote($noteID, $belongsTo)\" style=\"cursor:pointer;\">[delete comment]</span><br>$note";
  33. echo "</div>";
  34. }
  35. echo "<span class=\"cursor\" onClick=\"document.getElementById('noteForm').style.display=''\">add note</span>";
  36. echo "<div id=\"noteForm\" style=\"display:none;\">
  37. <label>
  38.   <textarea name=\"note\" cols=\"45\" rows=\"5\" class=\"notes\" id=\"note\"></textarea>
  39. </label>
  40.     <label><br>
  41.     </label>
  42.     <label>
  43.       <input type=\"button\" name=\"button2\" id=\"button2\" value=\"Nevermind\" onClick=\"document.getElementById('noteForm').style.display='none'\">
  44.     </label>
  45.   <input type=\"button\" name=\"button\" id=\"button\" value=\"Submit\" onClick=\"newNote('$belongsTo')\">";
  46.  
  47.           $query2 = "SELECT DISTINCT salesRepID FROM notes WHERE contactID = $contactID";
  48.         $result2 = mysql_query($query2) or die('Sorry, could not get entires at this time ');
  49.         while($row2=mysql_fetch_array($result2, MYSQL_ASSOC))
  50.    {
  51.        $salesRepID = $row2['salesRepID'];
  52.  
  53.        echo $userID;
  54.        echo "<br>";
  55.        echo $salesRepID;
  56.        if($salesRepID == $belongsTo){} else {
  57.  
  58.  
  59. $query1 = "INSERT INTO alertsNote (`alertID` ,`contactID` ,`toto` ,`from`) VALUES (NULL ,  '$contactID',  '$salesRepID',  '$salesRep')";
  60. $result1 = mysql_query($query1) or die('Our note system appears to be having issues.  One of the Matts probably broke it.');
  61.        }
  62.  
  63.    }
  64.  
  65.  
  66.  
  67. ?>
  68.  
It's a lot of code, so if you need something cleared up, let me know.

Thanks!
Apr 28 '11 #1
0 1147

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Gary Lundquest | last post by:
It appears to me that MySQL version 4 returns an error messge when doing an Insert that results in duplicate entries. Version 3 did NOT return an error - it dropped the duplicate entries and ran...
3
by: andreas.maurer1971 | last post by:
Hi all, since a few years I use the following statement to find duplicate entries in a table: SELECT t1.id, t2.id,... FROM table AS t1 INNER JOIN table AS t2 ON t1.field = t2.field WHERE...
4
by: MLH | last post by:
I never quite figured out how to reconfigure it to automatically delete redundant entries. Of course, one cannot always blatantly blow redundant records away w/o regard to which one it is that you...
4
by: sri2097 | last post by:
Hi all, I'm storing number of dictionary values into a file using the 'cPickle' module and then am retrieving it. The following is the code for it - # Code for storing the values in the file...
5
by: Chris Lasher | last post by:
Hello Pythonistas! I'm looking for a way to duplicate entries in a symmetrical matrix that's composed of genetic distances. For example, suppose I have a matrix like the following: A B ...
1
by: calebm12 | last post by:
Quick Question. I gotta a database with fields firstname, lastname, and hobby, etc. I dont want to allow duplicate entries for the name. For instance....no john smith twice....but there can be a...
5
by: Manish | last post by:
The topic is related to MySQL database. Suppose a table "address" contains the following records ------------------------------------------------------- | name | address | phone |...
12
by: joestevens232 | last post by:
Hello Im having problems figuring out how to remove the duplicate entries in an array...Write a program that accepts a sequence of integers (some of which may repeat) as input into an array. Write...
7
by: php_mysql_beginer911 | last post by:
Hi .. i am trying to update a table where if field contents any duplictaed entries than one of the field should be updated with random number which is unique so i can make all entries unique i...
0
by: niths | last post by:
hi all, i had a users page in which the Admin can add users.so while adding a user i am able to restrict the duplicate entries(same names).Those users will be displayed in a table, and there is a...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.