因此,對於我的學校作業之一,我一直在用戶輸入他們的生日後出現問題。我必須用2種方式迴應用戶。 1)如果日期等於他們的生日,他們會收到一個好消息,2)如果日期不等於他們的生日,那麼他們會得到不同的消息。如果日期等於他們的生日,如何回顯給用戶?
由於某種原因,我的if語句不工作...幫助?
這裏的if語句........
<?php
//if statement for birthday
$month = $_POST['month'];
$year = $_POST['year'];
$day = $_POST['day'];
$date = $year ."-". $month ."-".$day;
$date = date("Y-m-d",strtotime($date));
if(date('m-d') == date('m-d', $date)) {
// today is users birthday. show any message you want here.
echo "<p>Happy Birthday $firstname!</p>\n";
} else {
echo "<p>You were born $date.</p>\n";
}
?>
而且......這裏的下拉列表....
<?php
$months = array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
//1950 is standard year thing for most websites I've noticed
$yearFrom = 1950; // The first year included in the drop-down for years
// $yearFrom = date("Y")-80;
// Using this line instead, gives a dynamic range of years, always 80 years
// Echo out all years via a for-loop
//<select> IS the dropdown box
echo "<select name=\"year\" id=\"year\">";
//less than or equal to current year
for ($yearFrom; $yearFrom <= date("Y"); $yearFrom++) {
// Each $yearFrom represents a year, always incremented by 1 year
//echos out every year that we put present.......
echo "<option value=\"$yearFrom\">$yearFrom</option>";
}
echo "</select>";
// Echo out all months from the array $months
echo "<select name=\"month\" id=\"month\">";
foreach($months as $key=>$value) {
// $key is the index of the array, starting at 0
$numericMonth = $key + 1;
echo "<option value=\"$numericMonth\">$value</option>";
}
echo "</select>";
// Echo out all days (1-31) via a for-loop
echo "<select name=\"day\" id=\"day\">";
for ($i=1; $i <= 31; $i++) {
// Each $i represents a numeric value of days, from 1-31
echo "<option value=\"$i\">$i</option>";
}
echo "</select>";
?>
所以......這就是我有..所有的想法和援助非常感謝。 :)
您是否收到錯誤消息或輸出不是你期待什麼? – Lima
@利馬沒有錯誤。它輸出錯誤的信息。 – Sarah