Jump to content

[SOLVED] Array code not working correctly


acctman

Recommended Posts

why I run this array code below the month names show correctly but the number values are not correct. $_SESSION['month'] is equal to "2" for every month the value is shown as 2, why is this happening.

<?php
$months = array(
  1 => 'January',
  2 => 'February',
  3 => 'March',
  4 => 'April',
  5 => 'May',
  6 => 'June',
  7 => 'July',
  8 => 'August',
  9 => 'September',
  10 => 'Octobner',
  11 => 'November',
  12 => 'December' );
foreach ($months as $month_id => $month_name)
{
$selected = ($_SESSION['month'] == $month_id) ?' selected="selected"':'';
echo "<option value=\"$_SESSION['userid']\" $selected>$month_name</option>\n";
}
?>

 

this is what is being printed in the html. its repeating the selected value of "2"

<SPAN class=label>Birthday:</SPAN> <SPAN class=normal><SELECT 
name=add[month]><OPTION value=2>January</OPTION> <OPTION selected 
value=2>February</OPTION> <OPTION value=2>March</OPTION> <OPTION 
value=2>April</OPTION> <OPTION value=2>May</OPTION> <OPTION 
value=2>June</OPTION> <OPTION value=2>July</OPTION> <OPTION 
value=2>August</OPTION> <OPTION value=2>September</OPTION> <OPTION 
value=2>Octobner</OPTION> <OPTION value=2>November</OPTION> <OPTION 
value=2>December</OPTION></SELECT> </SPAN>

Link to comment
https://forums.phpfreaks.com/topic/128771-solved-array-code-not-working-correctly/
Share on other sites

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.