Page 1 of 1

UDT to check if data is in DB then return answer

Posted: Thu Apr 29, 2010 4:23 pm
by CMSmonkey
Forgive me for the wreck of a UDT below, but hey, I am trying.  ;)

I am using CMSMS 1.6.7 and FormBuilder 0.6.1

Here is what I want it to do:
The user is given a code that is stored in the database from a previous form entry.
In a subsequent form, the user will enter a code into a text field.  When the form is processed, the following UDT is called, and it will designate the price field (a hidden field) to be 75.00 (if the code is found in the database) or 95.00 (if the code is not found in the database).

Code: Select all

global $gCms;
$db =& $gCms->GetDb();

$code=$params['code'];
$price=$params['price'];

if ($_POST["code"]) {
    $conn= "mysql_connect('localhost', 'mysql_user', 'mysql_password')";
    $sql = "SELECT COUNT(1) AS matches FROM cms_module_fb_resp_val WHERE field_id=39 = '{$code}'";
    $result = mysql_query($conn, $sql);
    if ($row = mysql_fetch_assoc($result)) {
        $good = $row["matches"] >= 1;
    }
    mysql_free_result($result);
    
    if ($good) {
        $price="75.00";
    } else {
        $price="95.00";
    }
}
Somehow I can't get this to work though as the price field only comes back "[unspecified]".  Where did I go wrong?

Any help is appreciated.

Re: UDT to check if data is in DB then return answer

Posted: Thu Apr 29, 2010 4:27 pm
by calguy1000
This is a general programming question, not a CMSMS Specific question.
And it was placed in completely the wrong board.

Please ask general programming questions elsewhere.  Otherwise people will start asking all kinds of stupid stuff like auto repair questions etc, etc.

Re: UDT to check if data is in DB then return answer

Posted: Thu Apr 29, 2010 4:32 pm
by CMSmonkey
My bad - I thought it would be a Module question since I am working with FormBuilder.  My apologies.