close ad
Databridge V2 with MySQLi support IS Now Available!
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

I need to add an If statement before inserting a record

Thread began 8/09/2021 8:10 am by birdscreen398247 | Last modified 8/09/2021 1:55 pm by Ray Borduin | 25 views | 1 replies |

birdscreen398247

I need to add an If statement before inserting a record

I have an Insert Form that adds records to two tables.
The first insert query adds a record to PORC_records and captures the ID field.
I then have multiple fields on the form (Link1, Link2, Link3, etc.) which I want to add to the PORC_ebirdlinks table using the ID captured above and the contents of Link1, Link2, etc.

Each of those form fields will create a new record. So Link1 will be a record, Link2 will be a record, etc.

However, not all of those fields will have data, so I want an "if not null" type of condition before each of those insert queries.

I know the algorithm, just not the syntax for the coding.

I have only put two "Link" Insert Queries in so far. I will add the others once I have the "If" coding.

See attached code.

Sign in to reply to this post

Ray BorduinWebAssist

I think something like this would work for you:

php:
<?php

if (isset($_POST["submit"])) {
  
$InsertQuery = new WA_MySQLi_Query($siteguide2018);
  
$InsertQuery->Action "insert";
  
$InsertQuery->Table "PORC_records";
  
$InsertQuery->bindColumn("common_name""s""".((isset($_POST["species"]))?$_POST["species"]:"")  ."""WA_DEFAULT");
  
$InsertQuery->saveInSession("ID");
  
$InsertQuery->execute();
  
$InsertGoTo "";
  if (
function_exists("rel2abs")) $InsertGoTo $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
  
$InsertQuery->redirect($InsertGoTo);
}
?>
<?php
if ((isset($_POST["link1"]))?$_POST["link1"]:"") {
  
$InsertQuery = new WA_MySQLi_Query($siteguide2018);
  
$InsertQuery->Action "insert";
  
$InsertQuery->Table "PORC_ebirdlinks";
  
$InsertQuery->bindColumn("record_ID""s""".($_SESSION["ID"])  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("ebird_link""s""".((isset($_POST["link1"]))?$_POST["link1"]:"")  ."""WA_DEFAULT");
  
$InsertQuery->saveInSession("ID");
  
$InsertQuery->execute();
  
$InsertGoTo "";
  if (
function_exists("rel2abs")) $InsertGoTo $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
  
$InsertQuery->redirect($InsertGoTo);
}
?>
<?php
if ((isset($_POST["link2"]))?$_POST["link2"]:"") {
  
$InsertQuery = new WA_MySQLi_Query($siteguide2018);
  
$InsertQuery->Action "insert";
  
$InsertQuery->Table "PORC_ebirdlinks";
  
$InsertQuery->bindColumn("record_ID""s""".($_SESSION["ID"])  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("ebird_link""s""".((isset($_POST["link2"]))?$_POST["link2"]:"")  ."""WA_DEFAULT");
  
$InsertQuery->saveInSession("ID");
  
$InsertQuery->execute();
  
$InsertGoTo "";
  if (
function_exists("rel2abs")) $InsertGoTo $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
  
$InsertQuery->redirect($InsertGoTo);
}
?>
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...