[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

check for duplicate value in input

Posted on 2011-09-18
2
Medium Priority
?
313 Views
Last Modified: 2012-05-12
I have code that checks mysql for duplicate entries in a database and issues error through ajax. That works fine. My problem is that I have no way for checking duplicate entries in the form when the form is sent to php for processing. The inputs are created by a jquery change on a slider so there could many inputs created by the user from which they create unique codes. What I am trying to do is check that if a user enters the same number in the form then issue an error. Am I better doing this before it reaches php using jquery?  I hope someone can help with this. Thanks

$duplicates = array();

foreach ($boxnumber as $val)
{
if ( $val != "" )
 {
  mysql_select_db($database_logistor, $logistor);
  $sql = "SELECT custref FROM boxes WHERE custref='$val' and status = 'In'";
  $qry = mysql_query($sql) or die(mysql_error());

  if(mysql_num_rows($qry) < 1)
  {
  $duplicates[] = '[ '.$val.' ]';
  $flag=1;
  }
  
 }
}

Open in new window

0
Comment
Question by:peter_coop
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 10

Accepted Solution

by:
acbxyz earned 1000 total points
ID: 36556064
If you want to do this in PHP you can use array_unique()
$uniqueboxes = array_unique($boxnumber);
if (count($uniqueboxes) != count($boxnumber)) {
  // there are duplicate boxes typed in
  // if you want to know which:
  $dupinputs = array();
  foreach (array_count_values($boxnumber) as $box => $count) {
    if ($count > 1) {
      $dupinputs[] = $box;
    }
  }
  // since array_diff() ignores duplicate values on input array this doesn't work
  // $dupinputs = array_diff($boxnumber, $uniqueboxes);
}

Open in new window

0
 

Author Closing Comment

by:peter_coop
ID: 36556081
perfect. thank you
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This video teaches users how to migrate an existing Wordpress website to a new domain.
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question