title: Checking MySql for failed input to display
body: <p>I am trying to update my code where I need to display what field of MySql errored. The script checks MySql and if the result ==0 based on passing 3 variables, then the $outstring will send the error in the $outstring. This $outstring is handled by jQuery using data.opp to determine error or success and displays the result in a dialog window. What is happening is that all my fields are being displayed in the $outstring where I am looking only to display which field failed. </p>
  
  <p>What is the best way to proceed so I know which $variable is producing the 0 result and display just what part of the MySql failed. I have posted the relevant part of the code that handles this output. Many thanks.</p>
  
  <pre><code>&lt;?php
  
  $outString = ''; // NEED to do HTML output Formating on SERVER Side
      // Only Return a String to browser NOT an array
  
  
      foreach ($array as $box) {
          $box = mysql_real_escape_string($box);
          $sql = "SELECT custref,customer,department,status FROM boxes WHERE custref = '$box' ";
          $sql .= "AND customer = '$company' ";
          $sql .= "AND department = '$dept' ";
          $sql .= "AND status = '1' ";
          $result = mysql_query($sql) or die ('{"opp":"error","box":"' . mysql_error() . '"}');
  
          // If there are no entries, send output to outstring as error
          if (mysql_num_rows($result) == 0) {
  
              $outString .= $box . ' ';
              $outString .= $dept . ' ';
              $outString .= '1' . ' ';
  
  
      }   // foreach ($array
      }
      if ($outString) { // if there are numbers in this string, then there are error Duplicates
          $error = array('opp' =&gt; "error", 'box' =&gt; $outString); // box will have the TEXT for the Dialog Text
      // IMPORTANT, have changed JSON output to use an Opperation (opp) to indicate
      // in javascript if there was an error OR not
          $output = json_encode($error);
          echo $output;
          exit();
      }
  
  ?&gt;
  </code></pre>