title: PHP MySQL Delete record only if it exist
body: <p>Having a bit of trouble, I have created a form to deleted a record from a linked MySQL database using PHP that works, but I am having an problem with how to make an error display if a <strong>uadnumber</strong> value for example already exists.</p>
  
  <pre><code>&lt;form name="deleterecord" action="indexdelete.php" method="post"&gt;
    UAD Username: &lt;br/&gt;&lt;input type="text" name="uadnumber" /&gt;&lt;br/&gt;
    &lt;input type="submit" onclick="return deletedatabase();" value="Delete" /&gt;
  &lt;/form&gt;
  
  &lt;?php
    // find the values from the form
    $uadnumber = $_POST['uadnumber'] ;
  ?&gt;
  
  &lt;?php
      $con=mysqli_connect($db_hostname,$db_username,$db_password,$db_database);
      // Check connection
      if (mysqli_connect_errno())
        {
        echo "Failed to connect to MySQL: " . mysqli_connect_error();
        }
      $retval = mysqli_query($con,"DELETE FROM users WHERE uadnumber='$uadnumber'");
      if(!$retval&lt;0)
      {
        die('Could not delete data: ' . mysql_error());
      }
      echo "Deleted all linked data from user $uadnumber successfully"."&lt;br&gt;&lt;br&gt;";
      echo "&lt;hr&gt;";
      echo "Below is the remaining users within the database";
  
      mysqli_close($con);
  
      ?&gt;
  </code></pre>