Jump to content

Inserting Values From A Multiple Selection Box To a Database


lampquest

Recommended Posts

Hello guys,

  I need to be able take values from a multiple selection box in an html form and store it in my database. I was able to display the selected values on the browser(using associative array and loop)but need to be able to store it in the database also. Any help will be highly appreciated.

Kind regards.

Femi
[email protected]
Ok, we're going to need more information:

1) What database (mysql will be assumed)?
2) Do you have a connection to the database?
3) Do you know SQL (INSERT statements)?

It would also be helpful if you showed us your current code and database structure.

Thanks a bunch Ober.

1)It's a MySQL database.
2)have a connection to the database
3)and infact was able to insert data from all other fields in my form.

The only problem I have being able take all the values from a user's multiple selection and write it to the database field meant for that. If user selects 4 option values, my code is able to print all the selected values to the browser but not able all to the database....only one, ie the last selected option is being inserted.

This is how  my  current code looks like:

foreach ( $HTTP_POST_VARS as $key=>$value )
{
if ( gettype( $value ) == "array" )
{
print "$key == <br>";
foreach ( $value as $two_dim_value )


print ".........$two_dim_value<br>";



}
else
{
print "$key == $value<br>\n";
}
}


// insertion into database



$reg_date = date("Y-m-d");

$sql = "insert into agent (email, fname, lname, licence, bus_name, bus_phone, bus_address, state, mobile, password, region, date) values ('$email', '$fname', '$lname', '$license', '$bname', '$bphone', '$baddress', '$state', '$mphone', '$password', '$two_dim_value', '$reg_date')";

$result = mysql_query($sql);
if (!$result)
    {
echo "<center><font color='red'>Query Error</font><br><br> Error Inserting Entries !</center>";
    }
else
                  {

      // send a mail


                    }

The  $two_dim_value represents the selected values.

Any will be highly appreciated pls.

Femi

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.