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
femi@dnetsystems.net
Link to comment
Share on other sites

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.
Link to comment
Share on other sites


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
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.