Isaiaha Posted February 28, 2009 Share Posted February 28, 2009 Hi Thank you for your help in advance. I have an array generate drop down list and after form is submitted I'd like to have the value and not the key inserted into mysql - i have used array_value, implode and I either get a blank entry, 'array' entry, or the key. any help would be appreciated. $months = array (1=>'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'); if(isset($_POST['Submitted'])) { $sticky_months = $_POST['month']; } echo '<select id="size-1" name="month">'; echo '<option value="sm" >Select Month</option>'; foreach ($months as $key => $value) { if($key == $sticky_months) { echo '<option value="' . $key .'" selected>' . $value . '</option>'; }else{ echo '<option value="' . $key .'">' . $value . '</option>'; } } $query = "INSERT INTO summer09 (user_id, reg_date, month) VALUES (NULL, NOW(),'$month')"; Quote Link to comment https://forums.phpfreaks.com/topic/147345-solved-insert-php-array_values-instead-of-array_keys/ Share on other sites More sharing options...
Isaiaha Posted March 1, 2009 Author Share Posted March 1, 2009 Problem solved! - instead of using number keys use value keys! $months = array ('January' => January, 'February' => February, 'March' => March, 'April' => April, 'May' => May, 'June' => June, 'July' => July, 'August' =>August, 'September' => September, 'October' => October, 'November' => November, 'December' => December); Thanx Quote Link to comment https://forums.phpfreaks.com/topic/147345-solved-insert-php-array_values-instead-of-array_keys/#findComment-773874 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.