title: Using PHP to flag a form for insert or update function
body: <p>wondering what the the best way to achieve something is.</p>
  
  <p>To summarise, I have a form that I load by ajax which I use for to both update and insert new rows into a database. To determine whether it is an update or an insert I use the below code (updated forms use the mysql query to populate the form fields).</p>
  
  <p>My code seems sloppy and not best practice. Are there any other suggestion on what would be the best way to do this?</p>
  
  <pre><code>&lt;? 
  require_once("config.php");
  
  $insert = false;
  $update = false;
  $targID = 0;
  
  if(isset($_POST['targID'])){
  $targID =  $_POST['targID'];
  $targRow = mysql_fetch_array(mysql_query("select * from events where eventid=$targID"));
  $update = true;
  }else{
  $insert = true;
  }
  
  ?&gt;
  &lt;script type="text/javascript"&gt;
      var insert = &lt;? echo $insert; ?&gt;+0;
      var update = &lt;? echo $update; ?&gt;+0;
  
      ......javascript button events, validation etc based on inssert/update
  &lt;/script&gt;
  </code></pre>