Page 1 of 1

PHP Check for Record Exists

Unread postPosted: Tue Feb 03, 2015 9:08 pm
by mahmud
Hi,

I have tried to get some PHP code to check if a record exists before posting to a table, followed another example, but it posts even when it is not supposed to; when $rcount <> NULL. The code:
Code: Select all
function CheckRowSave(){
    $sqlCheckRow =  "SELECT COUNT(*) FROM hrectemp
JOIN hrecord ON hrecord_classid = '#RECORD_ID#' AND hrecord_date = hrectemp_date;" ;
nuRunQuery($sqlCheckRow);
$rcount = mysqli_num_rows($sqlCheckRow);
    nuDebug($rcount); //This will place the SQL query into the zzzsys_debug table for viewing.
    if (empty($rcount)) {
    savehrec();
    }
}

What am I doing wrong please?

Re: PHP Check for Record Exists

Unread postPosted: Tue Feb 03, 2015 9:09 pm
by mahmud
Forgot to mention, this is in the "Before Save" window of a form.

Re: PHP Check for Record Exists

Unread postPosted: Thu Feb 05, 2015 8:06 am
by admin
mahmud,

You might be better off doing something simpler like this..

Code: Select all

if('#this_field#' == ''){
   nuDisplayError("This Field cannot be left blank..");
}



If there are any error messages a record will not be updated or deleted.

http://wiki.nubuilder.net/index.php/PHP_Functions#nuDisplayError.28.24message.29

Here is more about where you can use hash variables.

http://wiki.nubuilder.net/index.php/Hash_Variables

Steven

Re: PHP Check for Record Exists

Unread postPosted: Sun Feb 08, 2015 12:13 am
by mahmud
Thanks for your response, but if you look at the code, I am trying to determine if a record already exists in a table so a user doesn't post it twice.

Mahmud

Re: PHP Check for Record Exists

Unread postPosted: Mon Feb 09, 2015 8:00 am
by admin
Mahmud,

I have no idea what you are attempting to do in you code.

The point I was trying to make is if you want nuBuilderPro to not save a record, have it create an error message.

Steven