Welcome to the nuBuilder forums!

Please register and login to view forums and other content only available to registered users.

PHP Check for Record Exists

Post Reply
mahmud
Posts: 7
Joined: Wed Dec 03, 2014 11:38 pm

PHP Check for Record Exists

Unread post 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?
Last edited by mahmud on Tue Feb 03, 2015 12:41 pm, edited 1 time in total.
mahmud
Posts: 7
Joined: Wed Dec 03, 2014 11:38 pm

Re: PHP Check for Record Exists

Unread post by mahmud »

Forgot to mention, this is in the "Before Save" window of a form.
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: PHP Check for Record Exists

Unread post 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
mahmud
Posts: 7
Joined: Wed Dec 03, 2014 11:38 pm

Re: PHP Check for Record Exists

Unread post 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
admin
Site Admin
Posts: 2781
Joined: Mon Jun 15, 2009 2:23 am
nuBuilder Version: 4.5
Been thanked: 1 time

Re: PHP Check for Record Exists

Unread post 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
Post Reply