title: Update a row if ID exists else Insert
body: <p>This is the code of a .php file. The column "memberid" has a unique index. When a user enters a record with an existing memberid, the record must get updated else a new row is created.</p>
  
  <p>I also want to show an alert box. For test purposes I added like the way below, but it is not firing. No message is displayed.</p>
  
  <p>I also want to know whether it is the right approach to handle insert/update automatically?</p>
  
  <pre><code>&lt;META http-equiv="refresh" content="2; URL=socialprofile.html"&gt;
  &lt;?php
  error_reporting(E_ALL ^ E_NOTICE);
  require_once("../Lib/dbaccess.php");
  
      //Retrieve values from Input Form
      $CandidateID = $_POST["inCandidate"];
      $SocialProfile = $_POST["inActivities"];
  
      $InsertQuery = "INSERT INTO candidate_db_social (memberid, socialactivities, lastupdated) VALUES (".$CandidateID.",'".$SocialProfile."',now())";
      $UpdateQuery = "UPDATE candidate_db_social SET socialactivities='".$SocialProfile."', lastupdated=now() WHERE memberid=".$CandidateID;
      try
      {
          $Result = dbaccess::InsertRecord($InsertQuery); 
      }
      catch(exception $ex)
      {
          $Result = dbaccess::InsertRecord($UpdateQuery);
          echo "&lt;script type='text/javascript'&gt;alert('".$ex."');&lt;/script&gt;";
      }
  ?&gt;
  </code></pre>