Welcome to Geeklog, Anonymous Friday, March 29 2024 @ 03:25 am EDT

Geeklog Forums

Another Question on Groups


Status: offline

rjrufo

Forum User
Regular Poster
Registered: 06/14/03
Posts: 95
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:
Text Formatted Code

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:
Text Formatted Code

    $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:
Text Formatted Code

    $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:
Text Formatted Code

    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... Embarassed
 Quote

Status: Banned

machinari

Forum User
Full Member
Registered: 03/22/04
Posts: 1512
try enclosing your $vars inside curly braces.
eg:
Text Formatted Code
...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...
 Quote

Status: offline

rjrufo

Forum User
Regular Poster
Registered: 06/14/03
Posts: 95
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?
 Quote

mach

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
Text Formatted Code
    $result = DB_query ("SELECT $selection FROM $table WHERE grp_name LIKE '%Region%' ORDER by grp_name");

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

 
 Quote

mach

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?
 Quote

mach

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:
Text Formatted Code
        DB_query("INSERT INTO {$_TABLES['group_assignments']}
        (ug_main_grp_id, ug_uid)
        VALUES ({$_POST['location_select']},$uid)");
 
 Quote

Status: offline

rjrufo

Forum User
Regular Poster
Registered: 06/14/03
Posts: 95
Mach,

Thank you very much!!! Big Celebration That worked!!!

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

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

Thanks again.
 Quote

All times are EDT. The time is now 03:25 am.

  • Normal Topic
  • Sticky Topic
  • Locked Topic
  • New Post
  • Sticky Topic W/ New Post
  • Locked Topic W/ New Post
  •  View Anonymous Posts
  •  Able to post
  •  Filtered HTML Allowed
  •  Censored Content