lampquest Posted January 29, 2007 Share Posted January 29, 2007 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. Femifemi@dnetsystems.net Quote Link to comment https://forums.phpfreaks.com/topic/36200-inserting-values-from-a-multiple-selection-box-to-a-database/ Share on other sites More sharing options...
ober Posted January 29, 2007 Share Posted January 29, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/36200-inserting-values-from-a-multiple-selection-box-to-a-database/#findComment-171968 Share on other sites More sharing options...
franz Posted January 29, 2007 Share Posted January 29, 2007 Look up "mysql_connect" at the php documentation ...You will find many examples on how to do that . Quote Link to comment https://forums.phpfreaks.com/topic/36200-inserting-values-from-a-multiple-selection-box-to-a-database/#findComment-171969 Share on other sites More sharing options...
lampquest Posted January 30, 2007 Author Share Posted January 30, 2007 Thanks a bunch Ober.1)It's a MySQL database.2)have a connection to the database3)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 Quote Link to comment https://forums.phpfreaks.com/topic/36200-inserting-values-from-a-multiple-selection-box-to-a-database/#findComment-172600 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.