close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

insert record if it doesn't already exist

Thread began 1/11/2022 9:07 am by birdscreen398247 | Last modified 1/11/2022 1:33 pm by Ray Borduin | 176 views | 3 replies |

birdscreen398247

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.

Sign in to reply to this post

Ray BorduinWebAssist

You could create a recordset filtered by the record number and then use the Recordset Empty trigger for the insert. Just make sure the recordset is above the insert in the code.

Sign in to reply to this post
Did this help? Tips are appreciated...

birdscreen398247

I know how to create the recordset, but what is the code for Recordset Empty?

If my recordset is rsRecordset1, then what do I put in front of the update query?

Sign in to reply to this post

Ray BorduinWebAssist

If you add the recordset, then open the Insert server behavior, then the trigger dropdown list should have "Recordset Empty" as an option.

Sign in to reply to this post
Did this help? Tips are appreciated...

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...