lampquest Posted January 30, 2007 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 == "; foreach ( $value as $two_dim_value ) print ".........$two_dim_value"; } else { print "$key == $value\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> 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 https://forums.phpfreaks.com/topic/36298-challenge-is-how-to-insert-values-from-the-multiple-selection-field-to-mysql/ Share on other sites More sharing options...
chronister Posted January 30, 2007 Share Posted January 30, 2007 You are looping through the array and replacing the value of $two_dim_value everytime it loops through hence at the end of the loop $two_dim_value is equal to the last option. In order to insert all values into 1 field, you will have to create a string out of them using something like implode()$new_string=implode(",", $array_name); /* this will place all values of an array into a string seperated by comma */ Link to comment https://forums.phpfreaks.com/topic/36298-challenge-is-how-to-insert-values-from-the-multiple-selection-field-to-mysql/#findComment-172608 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.