PHP Check for Record Exists

PHP Check for Record Exists

Unread postby mahmud » Tue Feb 03, 2015 9:08 pm

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?
Last edited by mahmud on Tue Feb 03, 2015 9:11 pm, edited 1 time in total.
mahmud
 
Posts: 7
Joined: Thu Dec 04, 2014 8:08 am

Re: PHP Check for Record Exists

Unread postby mahmud » Tue Feb 03, 2015 9:09 pm

Forgot to mention, this is in the "Before Save" window of a form.
mahmud
 
Posts: 7
Joined: Thu Dec 04, 2014 8:08 am

Re: PHP Check for Record Exists

Unread postby admin » Thu Feb 05, 2015 8:06 am

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
admin
Site Admin
 
Posts: 3406
Joined: Mon Jun 15, 2009 9:53 am
nuBuilder Version: 4.5

Re: PHP Check for Record Exists

Unread postby mahmud » Sun Feb 08, 2015 12:13 am

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
mahmud
 
Posts: 7
Joined: Thu Dec 04, 2014 8:08 am

Re: PHP Check for Record Exists

Unread postby admin » Mon Feb 09, 2015 8:00 am

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
admin
Site Admin
 
Posts: 3406
Joined: Mon Jun 15, 2009 9:53 am
nuBuilder Version: 4.5


Return to Custom Code

Who is online

Users browsing this forum: No registered users and 3 guests