Jump to content

[SOLVED] insert php array_values instead of array_keys


Isaiaha

Recommended Posts

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')";

Link to comment
Share on other sites

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

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.