Search the Community
Showing results for tags 'dupe'.
-
I have some code where a user can enter a file name/number separated by a comma. At the moment, I am checking for duplicate entries against a MySql database, which works well. However, I also need a way to check if a user has input the same entry so upon submission, example, a1b2c3,a1b2c3. I can catch this and trigger or echo an alert and halt the execution of the script. If there are no dupe entries, proceed to check db. I have been struggling with this and need to find a way to check before the check db code.I turn to the exerts for some guidance/assistance with this. I would be grateful for any help with this so I can move forward and learn something new in the process. Many thanks. <?php if (isset($_POST['file_add'])) { if (!empty($_POST['file_add'])) { $filedata = split(',', $_POST['file_add'][0]); $fileadd = array(); $fileduplicates = array(); foreach ($filedata as $val3) { if ($val3 != "") { $sql = "SELECT custref FROM files WHERE custref='$val3' AND customer = '" . $_SESSION['kt_idcode_usr'] . "'"; $qry = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($qry)) { $fileduplicates[] = $val3; } else { $fileadd[] = $val3; $flag = 1; } } else { $fileerror = '<span style="font-weight:bold;font-size:12px;color: #ff0000;">' . 'FILE ERROR! ' . '</span>' . '<span style="font-weight:normal;color: #000;background-color:#ffa;">' . 'You must enter a file for intake' . '</span>'; echo "<script language=\"JavaScript\">\n"; echo 'alert("FILE ERROR:\nYou must enter a file for intake.");'; echo " </script>"; echo $fileerror; } } if (count($fileadd)) { echo 'You wish to add file(s): ' . ' <div style="word-wrap:break-word;white-space: pre-wrap;overflow:auto !important;height: 100px; width: 250px; border: 1px solid #666; background-color: #fff; padding: 4px;">' . '<span style="font-weight:bold;color: #000;">' . join(', ', $fileadd) . '</span>' . '</div> ' . ' <p /> '; //if(count($duplicates) == 0) // add to session only if we have no duplicates $_SESSION['file_add'] = $fileadd; /// change here, do not store $_POST since it can contain duplicates } if (count($fileduplicates)) { $filedupeerror = "ERROR:" . " " . "File" . " " . '(' . join(', ', $fileduplicates) . ')' . " " . "This file is already in the database"; echo "<script language=\"JavaScript\">\n"; echo 'alert("FILE ERROR:\nThis file is already in the database");'; echo " </script>"; echo $filedupeerror; } } } ?>
- 3 replies
-
- php
- duplicates
-
(and 1 more)
Tagged with: