UDT to check if data is in DB then return answer

The place to talk about things that are related to CMS Made simple, but don't fit anywhere else.
Post Reply
CMSmonkey
Power Poster
Power Poster
Posts: 290
Joined: Thu Nov 27, 2008 4:58 pm

UDT to check if data is in DB then return answer

Post 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.
calguy1000
Support Guru
Support Guru
Posts: 8169
Joined: Tue Oct 19, 2004 6:44 pm

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

Post 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.
Follow me on twitter
Please post system information from "Extensions >> System Information" (there is a bbcode option) on all posts asking for assistance.
--------------------
If you can't bother explaining your problem well, you shouldn't expect much in the way of assistance.
CMSmonkey
Power Poster
Power Poster
Posts: 290
Joined: Thu Nov 27, 2008 4:58 pm

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

Post by CMSmonkey »

My bad - I thought it would be a Module question since I am working with FormBuilder.  My apologies.
Post Reply

Return to “The Lounge”