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

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

Archived

This topic is now archived and is closed to further replies.

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