Page 1 of 1

PHP Check for Record Exists

Posted: Tue Feb 03, 2015 12:38 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

Posted: Tue Feb 03, 2015 12:39 pm
by mahmud
Forgot to mention, this is in the "Before Save" window of a form.

Re: PHP Check for Record Exists

Posted: Wed Feb 04, 2015 11:36 pm
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 ... message.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

Posted: Sat Feb 07, 2015 3:43 pm
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

Posted: Sun Feb 08, 2015 11:30 pm
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