Page 1 of 1

Select Lists (Multiple) - I can't get em to store the values

Posted: Wed Jan 28, 2004 6:01 pm
by kanshou
Hey all, hope someone can offer a little bit of help and advice. I am trying to use a program called WebCalendar and it allows for adding events to a calendar.. pretty simple.. When a user clicks on a date, they open up a form and in this form can put in information for an event that gets logged on that date.

With the program came a way to add an array that allowed for making a new form field. One of those was a selectlist where one should be able to select multiple items from that list that get logged. (ie room reservations.) The list displays just fine, but even when multiple items are selected, only one shows up(or is even stored in the mysql database).

A couple chunks of code effect that.. in an extras file is:


Code: Select all

<?php
--------------------------------------------------------------------------------
 
$site_extras = array ( 
   array ( 
     "RoomName",       // unique name of this extra field (used in db) 
     "Room Name",           // how this field will be described to users 
     $EXTRA_SELECTLIST,    // type of field 
                           // List of options (first will be default) 
     array ( "None", "room1", "room11", "room12", "room13" ), 
     0                     // arg 2 (unused) 
   ) 
 );

--------------------------------------------------------------------------------
?>

In an entry file that controls the display from the above array is:

Code: Select all

<?php
--------------------------------------------------------------------------------
 
} else if ( $extra_type == $EXTRA_SELECTLIST ) { 
    // show custom select list. 
    echo "<SELECT NAME="" . $extra_name . "" MULTIPLE>"; 
    if ( is_array ( $extra_arg1 ) ) { 
      for ( $j = 0; $j < count ( $extra_arg1 ); $j++ ) { 
        echo "<OPTION"; 
        if ( ! empty ( $extras[$extra_name]['cal_data'] ) && 
          $extra_arg1[$j] == $extras[$extra_name]['cal_data'] ) 
          echo " SELECTED"; 
        echo " >" . $extra_arg1[$j] . "</OPTION>\n"; 
      } 
    } 
    echo "</SELECT>"; 
  }

--------------------------------------------------------------------------------
?>

And lastly in a backend functionality file is an IF statement that has this in it for its control:


Code: Select all

<?php
--------------------------------------------------------------------------------
 
$extra_type == $EXTRA_SELECTLIST) { 
        $sql = "INSERT INTO webcal_site_extras " . 
          "( cal_id, cal_name, cal_type, cal_data ) VALUES ( " . 
          "$id, '$extra_name', $extra_type, '$value' )";

--------------------------------------------------------------------------------
?>


Can anyone see why only one selected item is being inserted into the DB and not the multiple items that can be selected? Thanks so much for the help!

?>

Posted: Wed Jan 28, 2004 8:29 pm
by DuFF
Whats the DB field set as?

Posted: Wed Jan 28, 2004 10:01 pm
by kanshou
if I read it right, its

Code: Select all

['cal_data']

Posted: Thu Jan 29, 2004 10:27 am
by kanshou
the type is Text as well. I tried a few other options but that didn't seem to make a difference. Any ideas how to get the item to take multiple selections and store them? This is just a basic form, nothing fancy.. just has a number of items and you can click (hghlight) each one which should allow more than one to be chosen.

Posted: Thu Jan 29, 2004 11:20 am
by kanshou
I looked around and found a few examples with html forms working with php to do this, but I have a php form and need it to have a multiple select list, where you select multiple items and they go into the mysql database. I can't be the only one out there that has a need for this.

Posted: Thu Jan 29, 2004 5:12 pm
by DuFF
I think it has something to do with this piece of code:

Code: Select all

<?php
--------------------------------------------------------------------------------

$extra_type == $EXTRA_SELECTLIST) {
        $sql = "INSERT INTO webcal_site_extras " .
          "( cal_id, cal_name, cal_type, cal_data ) VALUES ( " .
          "$id, '$extra_name', $extra_type, '$value' )";

--------------------------------------------------------------------------------
?>
its hard to know what exactly is the root of the problem without seeing the DB setup and the extra code that surrounds these 3 parts.
I'd like to help so try IM'ing me next time I'm on AIM. My AIM name is right below this post.