Subject: Another Question on Groups

Posted on: 15/12/04 08:20pm
By: rjrufo

I thought I had everything right, but apparently not. I'm trying to add a select menu to the registration form using the custom registration code. Actually, I have the menu working correctly, but when I try registering, I get an SQL error indicating that the option value isn't being translated to the query.

Can someone direct me where I need to go for this? The code I'm working with - which is a modification to COM_optionList - and is located just above the custom_userform function is:
function COM_locationList( $table, $selection, $selected='', $sortcol=1 )
{
    $retval = '';

    $tmp = str_replace( 'DISTINCT ', '', $selection );
    $select_set = explode( ',', $tmp );

    $result = DB_query ("SELECT $selection FROM $table WHERE grp_name LIKE '%Region%' ORDER by grp_name");
    $nrows = DB_numRows( $result );

    for( $i = 0; $i < $nrows; $i++ )
    {
        $A = DB_fetchArray( $result );
        $retval .= '<option value="' . $A[0] . '"';

        if( $A[0] == $selected )
        {
            $retval .= ' selected="selected"';
        }

        $retval .= '>' . $A[1] . '</option>' . LB;
    }

    return $retval;
}



I then have this within the custom_userform function:
    $selection = '<select name="location_select">' . LB;
    $selection .= COM_locationList ($_TABLES['groups'], 'grp_id,grp_name',  $A['grp_id']);
    $selection .= '</select>';



To add the select list to the template, I added this:
    $user_templates->set_var('message', $message); 
    $user_templates->set_var('location_selector', $selection);
    $user_templates->set_var('ug_main_grp_id', $A['0']);



I then have the DB_query under the custom_usercreate function:
    DB_query("INSERT INTO {$_TABLES['group_assignments']}
    	(ug_main_grp_id, ug_uid)
    	VALUES ($A[0],$uid)");



Obviously, $A[0] isn't what I need in the query, but I've tried pretty much every thing else. Anyone have any ideas?

And please, I already feel stupid from another question I asked earlier, so if I'm missing something obvious, please break it to me gently...

Another Question on Groups

Posted on: 16/12/04 01:22am
By: machinari

try enclosing your $vars inside curly braces.
eg:
...VALUES ({$A[0]},{$uid})");

etc.
see if that makes any difference. take note of how your table name is enclosed in curly braces--make your other $vars the same whenever they appear in your sql statements.

but i could be wrong...

Another Question on Groups

Posted on: 16/12/04 04:59pm
By: rjrufo

Thanks Machinari,

But I've tried just about everything, even changing the values to something else. The $uid shows up in the error log, but the value for grp_id is blank, causing the error. Looking at the source of the page that is displayed in my browser, the option values are there - and are correct - but I'm not able to pass the selected value to the DB_query for some reason.

Any other ideas?

Another Question on Groups

Posted on: 16/12/04 07:01pm
By: Anonymous

try returning yout $_POST array to see if your numbers are making it into that.
eg, return print_r($_POST);

and/or returning your sql statement similarily just to see what the script is seeing and working with or not.

oh, and note this discrepency re the var $selection. should this
    $result = DB_query ("SELECT $selection FROM $table WHERE grp_name LIKE '%Region%' ORDER by grp_name");

be something like
    $result = DB_query ("SELECT $select_set FROM $table WHERE grp_name LIKE '%Region%' ORDER by grp_name");


Another Question on Groups

Posted on: 16/12/04 07:10pm
By: Anonymous

oh forget my last...
$tmp and $select_set seem not to be getting used anyway.
and $select+_set is an array anyway so I dunno what's going on there. Is that just left over from the original function?

Another Question on Groups

Posted on: 16/12/04 07:23pm
By: Anonymous

ok, forget my babling...
if you want the value of $A[0], then you need the $_POST value, which should be $_POST['location_select']

so use this query:
        DB_query("INSERT INTO {$_TABLES['group_assignments']}
    	(ug_main_grp_id, ug_uid)
    	VALUES ({$_POST['location_select']},$uid)");

Another Question on Groups

Posted on: 16/12/04 07:29pm
By: rjrufo

Mach,

Thank you very much!!! That worked!!!

Did I say thank you? Well, I'll say it again - THANK YOU!!!

I've been going round and round for a couple of days, and now it works!

Thanks again.

Geeklog - Forum
https://www.geeklog.net/forum/viewtopic.php?showtopic=44780