0

In an attempt to use selection lists in php ,i tried it for displaying date on a web page

<?php
echo"<html>
<head><title>Select a Date  </title></head>
<body>";
$monthname=array(1=>"January","Februray","March","April","May","June","July","August","September","October","November","December");
 $time=time();
 $today_date=date("M-d-Y",$time); //returns the current date
 echo "<div style='text-align:center'>\n";
 echo "<h3>Today is $today_date</h3><hr />\n";
 echo "<form action='process_form_date.php' method='POST'>\n";
 //selection list for month
 $todayMO=date("M",$time); //returns the current month
 echo "<select name='dateMonth'>\n";
 for ($M=1;$M<=12;$M++)
 {
  echo "<option value = $M";
  if($todayMO == $M)
   echo "selected";
   echo "> $monthname[$M]\n</option>"; 
 }
   echo "</select>\n";

 //selection list for day
 $todayDay=date("d",$time);
 echo "<select name='dateDay'>\n";
 for($n=1;$n<=31;$n++)
 {
   echo "<option value = $n";
   if($todayDay == $n)
     echo "selected";
 echo ">$n</option>\n";
 }
  echo "</select>\n";

 //selection list for year
 $todayYear=date("y",$time);
 echo "<select name='dateYear'>\n";
 for($n=$todayYear;$n<=$todayYear+3;$n++)
 {

   echo "<option value = $n";
   if($todayYear == $n)
     echo "selected";
 echo ">$n</option>\n";
 }
  echo "</select>\n";
  echo "</form></div>\n";
 ?>

</body>
</html>

But this code is not using the 'select' option to display today's date in a selection list but rather displaying for me
January-1-2014(default in code.)
How to get it?
a3c031e6a8b7a57aef51ceb9b783667e

Edited by javed.iqbal.3979: Pic upload

2
Contributors
5
Replies
23
Views
3 Years
Discussion Span
Last Post by javed.iqbal.3979
0

You are missing a space in following places
Use

echo "<option value = $M ";

instead of

echo "<option value = $M";

Use

echo "<option value = $n ";

instead of

echo "<option value = $n";

Use

echo "<option value = $n ";

instead of

echo "<option value = $n";
1

You are missing a space in following places
Use

echo "<option value = $M ";

instead of

echo "<option value = $M";

Use

echo "<option value = $n ";

instead of

echo "<option value = $n";

Use

echo "<option value = $n ";

instead of

echo "<option value = $n";
1

Yep.. You have to get the integer value of the month.

Use

$todayMO=date("m",$time);

instead of

$todayMO=date("M",$time);
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.