insert record if it doesn't already exist
I want to insert a record only if the record does not already exist.
I found a thread on this topic, but could not parse out the code that I need.
Here is my InsertQuery code
<?php
if (($_SERVER["REQUEST_METHOD"] === "POST") && (isset($_SERVER["HTTP_REFERER"]) && strpos(urldecode($_SERVER["HTTP_REFERER"]), urldecode($_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"])) > 0) && isset($_POST)) {
  $InsertQuery = new WA_MySQLi_Query($siteguide2018);
  $InsertQuery->Action = "insert";
  $InsertQuery->Table = "PORC_decisions";
  $InsertQuery->bindColumn("record_number", "s", "".((isset($_POST["record_number"]))?$_POST["record_number"]:"")  ."", "WA_DEFAULT");
  $InsertQuery->saveInSession("");
  $InsertQuery->execute();
  $InsertGoTo = "PORC_Admin_New_Records.php";
  if (function_exists("rel2abs")) $InsertGoTo = $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
  $InsertQuery->redirect($InsertGoTo);
}
?>
I only want it to run if a record with the record_number field does not already match the record_number field on the form.
Note: the record_number field is a Primary field. So right now, if I try to submit the page and the record_number exists, all I get is a SQL error message.
So if there is a way to use the primary field property in this procedure, maybe that is the simplest solution.


