Trying to generate error messages from array items, maybe I'm on the wrong track

I need to generate an error message when an invalid date is chosen from select lists. I have set up arrays for the $days,$years,$months but I can’t get my head wrapped around how to set up the error message. For example, a leap year could not be 2/30/2012. This is in 4 files. I am only including the file for the form and the validation. I have commented out one thing I tried, and deleted the code to access the other two files. I feel like I should combine $days,$years,$months into one multidimensional array and I’ve tried but my lack of knowledge keeps me from pulling it all together with the error codes either way. Any help is much appreciated.

1st File:

<!

[php]<?php

//------setup for year array -----
$years = array(“1953”,“1954”,“1955”,“1956”,“1957”,“1958”,“1959”,
“1960”,“1961”,“1962”,“1963”,“1964”,“1965”,“1966”,“1967”,“1968”,“1969”,
“1970”,“1971”,“1972”,“1973”,“1974”,“1975”,“1976”,“1977”,“1978”,“1979”,
“1980”,“1981”,“1982”,“1983”,“1984”,“1985”,“1986”,“1987”,“1988”,“1989”,
“1980”,“1991”,“1992”,“1993”,“1994”,“1995”,“1996”,“1997”,“1998”,“1999”,
“2000”,“2001”,“2002”,“2003”,“2004”,“2005”,“2006”,“2008”,“2009”,“2010”,
“2011”,“2012”,“2013”);
//-----set up for days array-----
$days = array(“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”,“11”,“12”,“13”,“14”,“15”,“16”,
“17”,“18”,“19”,“20”,“21”,“22”,“23”,“24”,“25”,“26”,“27”,“28”,“29”,“30”,“31”);
//-------set up for month array-------
$months = array(“January”,“February”,“March”,“April”,“May”,“June”,
“July”,“August”,“September”,“October”,“November”,“December”);
?>[/php]


//

Assignment 7_1

Enter your date of birth and I will tell you your zodiac sign!

Select Year [php]<?php for($i=0; $i <?php echo $years[$i] ?> <?php } ?>[/php]
Select Month [php]<?php for($i=0; $i <?php echo $months [$i] ?> <?php } ?>
Select Day of Month <?php for($i=0; $i <?php echo $days [$i] ?> <?php } ?>[/php]
[u][b]end of 1st file[/b][/u]

2ndFile:

Web 220 Assignment7_2.php

[php]<?php //-----retrieve form data----- $firstyear=$_REQUEST ["firstyear"]; $firstmonth=$_REQUEST ["firstmonth"]; $firstday=$_REQUEST ["firstday"];

//-----setup for variables-----

$years= array(“1953”,“1954”,“1955”,“1956”,“1957”,“1958”,“1959”,
“1960”,“1961”,“1962”,“1963”,“1964”,“1965”,“1966”,“1967”,“1968”,“1969”,
“1970”,“1971”,“1972”,“1973”,“1974”,“1975”,“1976”,“1977”,“1978”,“1979”,
“1980”,“1981”,“1982”,“1983”,“1984”,“1985”,“1986”,“1987”,“1988”,“1989”,
“1980”,“1991”,“1992”,“1993”,“1994”,“1995”,“1996”,“1997”,“1998”,“1999”,
“2000”,“2001”,“2002”,“2003”,“2004”,“2005”,“2006”,“2008”,“2009”,“2010”,
“2011”,“2012”,“2013 !? ! ? Dorian Grey is just a myth quit screwing around”);
$months=array(“January”,“February”,“March”,“April”,“May”,“June”,
“July”,“August”,“September”,“October”,“November”,“December”);
$days=array (“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”,“11”,“12”,“13”,“14”,“15”,“16”,
“17”,“18”,“19”,“20”,“21”,“22”,“23”,“24”,“25”,“26”,“27”,“28”,“29”,“30”,“31”);
$zodiac= array(“month0”,“month01”,“month02”,“month03”,“month04”,“month05”,“month06”,“month07”,
“month08”,“month09”,“month10”,“month11”);

$images= “months$zodiac.png”;//(“month0.jpg,”“month01.jpg,”“month02.jpg,”“month03.jpg,”“month04.jpg,”“month05.jpg,”
//“month06.jpg,”“month07.jpg,”“month08.jpg,”“month09.jpg,”“month10.jpg,”“month11.jpg,”);
//$zodiac=array(‘years’=>$years, ‘months’=>$months, ‘days’=>$days);
$dayName=$days[$firstday];
$moName=$months[$firstmonth];
$yrName=$years[$firstyear];
$Date= $firstday+$firstmonth+$firstyear;
$invalidDate = array(‘2 29 1956’,‘2 29 1960’,‘2 29 1964’,‘2 29 1968’,‘2 29 1972’,‘2 29 1976’,
‘2 29 1980’,‘2 29 1984’,‘2 29 1988’,‘2 29 1984’,‘2 29 1988’,‘2 29 1992’,‘2 29 1996’,‘2 29 2000’,
‘2 29 2004’,‘2 29 2008’,‘2 29 2012’,‘2 30 years’,‘2 31 years’, ‘9 31 years’,‘4 31 years’,‘6 31 years’,‘11 31 years’);

//-----error message management-----
//$error=’’;
//$i=1;
//$errorMsg=’’;
//foreach ($invalidDate as $value )

//$Date= false;
//
//if ($invalidDate==true)
// {
// $errorMsg = “Invalid Date!”;
// $Date= false;
// }
// else
// {
// $errorMsg= “

You entered the following date !

”;
//}
?>[/php]
[php]

<?php echo $dayName?> <?php echo $moName?> <?php echo $yrName?>[/php]

Your Zodiac Sign is:

[php]zodiac
[/php]
hello Odemar, i hope your first file working fine. replace your 2ndFile code with below code

USE BELOW CODE
[php]

<?php //-----retrieve form data----- $firstyear=$_REQUEST["firstyear"]; $firstmonth=$_REQUEST["firstmonth"]; $firstday=$_REQUEST["firstday"]; //-----setup for variables----- $years= array("1953","1954","1955","1956","1957","1958","1959","1960","1961","1962","1963","1964","1965","1966","1967","1968","1969","1970","1971","1972","1973","1974","1975","1976","1977","1978","1979", "1980","1981","1982","1983","1984","1985","1986","1987","1988","1989","1980","1991","1992","1993","1994","1995","1996","1997","1998","1999","2000","2001","2002","2003","2004","2005","2006","2008","2009","2010", "2011","2012","2013 !? ! ? Dorian Grey is just a myth quit screwing around"); $months=array("January","February","March","April","May","June","July","August","September","October","November","December"); $days=array ("1","2","3","4","5","6","7","8","9","10","11","12","13","14","15","16","17","18","19","20","21","22","23","24","25","26","27","28","29","30","31"); $zodiac= array("month0","month01","month02","month03","month04","month05","month06","month07","month08","month09","month10","month11"); $images= "months$zodiac.png";//("month0.jpg,""month01.jpg,""month02.jpg,""month03.jpg,""month04.jpg,""month05.jpg," //"month06.jpg,""month07.jpg,""month08.jpg,""month09.jpg,""month10.jpg,""month11.jpg,"); //$zodiac=array('years'=>$years, 'months'=>$months, 'days'=>$days); $dayName=$days[$firstday]; $moName=$months[$firstmonth]; $yrName=$years[$firstyear]; //$Date= $firstday+$firstmonth+$firstyear; $Date= $firstday.' '.$firstmonth.' '.$firstyear; $invalidDate = array('2 29 1956','2 29 1960','2 29 1964','2 29 1968','2 29 1972','2 29 1976', '2 29 1980','2 29 1984','2 29 1988','2 29 1984','2 29 1988','2 29 1992','2 29 1996','2 29 2000', '2 29 2004','2 29 2008','2 29 2012','2 30 *years*','2 31 *years*', '9 31 *years*','4 31 *years*','6 31 *years*','11 31 *years*'); if (in_array($Date, $invalidDate)) { echo "**Invalid Date!**

You entered the following date = ".$Date."

"; } else { echo "

You entered the following date = ".$Date."

" } ?>

[/php]
i hope this will helpful for you…
Replay your feedback.
SR

This is so very close, but I can tell that it is still scrolling through the indexes because, for example. if I select February 31 2012 it returns this: You entered the following date = 30 1 58. I think maybe I need to switch the two error codes around as well, but I didn’t until I fix the other problem. what do you think I am still missing?
Thanks for putting me back on the right direction.

Hello Odemar, i think there is need to refine both files again with proper logic and syntax. i found that there is many syntax error. please post latest code so i can suggest you much better. ~~SR~~ :) :)

Sorry I took so long to get back, I took a few unexpected days off.
I took your advice and went back through my code. Syntax is not a strong suit with me. Maybe if it was I wouldn’t be here. I did clean it up some though and that got me to understand something about how I was calling from the array and it now holds the dates entered and not the positions in the arrays.

The problem seems to be centered around the loop where I am trying to generate error messages, and or the way in which I have populated the $invalidDate array. As I have it now I don’t get parsing errors when I run it so I think my syntax is pretty good. I have tried several array functions and different loops though and nothing seems to work. l am sorry, but I’m at a loss. Here is what I have now. After this I will be adding functionality to display the zodiac sign images. I have them commented out for now.

File 1 (input):

PHP/Web220 Assignment7_1.php <!

[php]<?php

//------setup for year array -----
$years = array(“1953”,“1954”,“1955”,“1956”,“1957”,“1958”,“1959”,
“1960”,“1961”,“1962”,“1963”,“1964”,“1965”,“1966”,“1967”,“1968”,“1969”,
“1970”,“1971”,“1972”,“1973”,“1974”,“1975”,“1976”,“1977”,“1978”,“1979”,
“1980”,“1981”,“1982”,“1983”,“1984”,“1985”,“1986”,“1987”,“1988”,“1989”,
“1980”,“1991”,“1992”,“1993”,“1994”,“1995”,“1996”,“1997”,“1998”,“1999”,
“2000”,“2001”,“2002”,“2003”,“2004”,“2005”,“2006”,“2008”,“2009”,“2010”,
“2011”,“2012”,“2013”);
//-----set up for days array-----
$days = array(“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”,“11”,“12”,“13”,“14”,“15”,“16”,
“17”,“18”,“19”,“20”,“21”,“22”,“23”,“24”,“25”,“26”,“27”,“28”,“29”,“30”,“31”);
//-------set up for month array-------
$months = array(“January”,“February”,“March”,“April”,“May”,“June”,
“July”,“August”,“September”,“October”,“November”,“December”);
?>[/php]

Assignment 7_1

<span style='text-align:center; color:blue;'>
    <h1> Enter your date of birth and I will tell you your zodiac sign!</h1>
</span>

[php]

  <tr>
      <td>Select Month</td>
      <td><select name= "firstmonth">
          <?php
          for($i=0; $i<count($months); $i++)
          {
          ?>
          <option value ='<?php echo $i?>' selected = "selected">
              <?php echo $months [$i] ?></option>
              <?php
              }
              ?>
      </select>
      </td>
  </tr>    
   <tr>
      <td>Select Day of Month</td>
      <td><select name= "firstday">
          <?php
          for($i=0; $i<count($days); $i++)
          {
          ?>
          <option value ='<?php echo $i?>' selected = "selected">
              <?php echo $days [$i] ?></option>
              <?php
              }
              ?>
      </select>
      </td>
  </tr>
Select Year <?php for($i=0; $i <?php echo $years[$i] ?> <?php } ?>
[/php]

File 2(Response):

Web 220 Assignment7_2.php

Response from Assignment 7_2

[php]<?php include ("web220_header.html");

//-----retrieve form data-----
$firstyear=$_REQUEST [“firstyear”];
$firstmonth=$_REQUEST [“firstmonth”];
$firstday=$_REQUEST [“firstday”];

//-----setup for variables-----
$years= array(“1953”,“1954”,“1955”,“1956”,“1957”,“1958”,“1959”,
“1960”,“1961”,“1962”,“1963”,“1964”,“1965”,“1966”,“1967”,“1968”,“1969”,
“1970”,“1971”,“1972”,“1973”,“1974”,“1975”,“1976”,“1977”,“1978”,“1979”,
“1980”,“1981”,“1982”,“1983”,“1984”,“1985”,“1986”,“1987”,“1988”,“1989”,
“1980”,“1991”,“1992”,“1993”,“1994”,“1995”,“1996”,“1997”,“1998”,“1999”,
“2000”,“2001”,“2002”,“2003”,“2004”,“2005”,“2006”,“2008”,“2009”,“2010”,
“2011”,“2012”,“2013 !? ! ? Dorian Grey is just a myth quit screwing around”);
$months=array(“January”,“February”,“March”,“April”,“May”,“June”,
“July”,“August”,“September”,“October”,“November”,“December”);
$days=array (“1”,“2”,“3”,“4”,“5”,“6”,“7”,“8”,“9”,“10”,“11”,“12”,“13”,“14”,“15”,“16”,
“17”,“18”,“19”,“20”,“21”,“22”,“23”,“24”,“25”,“26”,“27”,“28”,“29”,“30”,“31”);
$zodiac= array(“month0”,“month01”,“month02”,“month03”,“month04”,“month05”,“month06”,“month07”,
“month08”,“month09”,“month10”,“month11”);

$images= “months$zodiac.png”;//(“month0.jpg,”“month01.jpg,”“month02.jpg,”“month03.jpg,”“month04.jpg,”“month05.jpg,”
//“month06.jpg,”“month07.jpg,”“month08.jpg,”“month09.jpg,”“month10.jpg,”“month11.jpg,”);
//$zodiac=array(‘years’=>$years, ‘months’=>$months, ‘days’=>$days);
$dayName=$days[$firstday];
$moName=$months[$firstmonth];
$yrName=$years[$firstyear];

$Date=$dayName.’ ‘.$moName.’ '.$yrName;
$invalidDate = array(‘2 29 1956’,‘2 29 1960’,‘2 29 1964’,‘2 29 1968’,‘2 29 1972’,‘2 29 1976’,
‘2 29 1980’,‘2 29 1984’,‘2 29 1988’,‘2 29 1984’,‘2 29 1988’,‘2 29 1992’,‘2 29 1996’,
‘2 29 2000’,‘2 29 2004’,‘2 29 2008’,‘2 29 2012’,‘2 30 years’,‘2 31 years’,
‘9 31 years’,‘4 31 years’,‘6 31 years’,‘11 31 years’);
?>[/php]

[php]<?php
//-----error message management-----
if (in_array($Date,$invalidDate)) {
echo “<span style= text-align’center’ font-size ‘24px’>Invalid Date!

”.$Date."

";
}
else
{ echo “

You entered the following date: “.$Date.”

”;
}
?>
    <p>Your Zodiac Sign is:</p> 
   <img src ='<?php echo$zodiac ?>' alt = "zodiac"/>[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service