Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Can someone pleaseee tell me what am I doing wrong with this code? The php part

ID: 3818154 • Letter: C

Question

Can someone pleaseee tell me what am I doing wrong with this code? The php part changes when I save the entire file as html. Im not sure what the problem is? Id appreciate a second set of eyes! Thank you!

<!DOCTYPE html>
<html>
<head>
    <title>Birthday</title>
<link rel="stylesheet" type="text/css" href="styles.css">
<h1>Is Today Your Birthday?!!</h1>
</head>
<body>

<?php

if(isset($_POST['sub']))

{

$mm=$_POST['mm'];

$dd=$_POST['dd'];

$yy=$_POST['yy'];

$dob=$mm   ."/".$dd."/".$yy;

$arr=explode('/',$dob);

//$dateTs=date_default_timezone_set($dob);
$dateTs=strtotime($dob);

$now=strtotime('today');

if(sizeof($arr)!=3) die('ERROR:please entera valid date');

if(!checkdate($arr[0],$arr[1],$arr[2])) die('PLEASE: enter a valid dob');

if($dateTs>=$now) die('ENTER a dob earlier than today');

$ageDays=floor(($now-$dateTs)/86400);

$ageYears=floor($ageDays/365);

$ageMonths=floor(($ageDays-($ageYears*365))/30);

echo "<font color='red' size='10'> You are $ageYears years old. </font>";
    if($mm==$arr[0])
     {
        if($dd==$arr[1])
        echo"<br><font color='red' size='10'>Today is your birthday</font>";
    }  
}

?>

<form method="post"><center>

Enter your DOB

<select name="yy">
<option value="">Year</option>
<?php
for($i=1899;$i<=2017;$i++)
{
echo "<option value='$i'>$i</option>";
}
?>
</select>


<select name="mm">
<option value="">Month</option>
<?php
for($i=1;$i<=12;$i++)
{
echo "<option value='$i'>$i</option>";
}
?>
</select>


<select name="dd">
<option value="">Date</option>
<?php
for($i=1;$i<=31;$i++)
{
echo "<option value='$i'>$i</option>";
}

?>
</select>

<input type="submit" name="sub" value="check it"/>

</center>

</form>

</body>
   <br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<audio autoplay="" controls="">
  <source src="file:///C:/Users/Jennifer/Downloads/Happy-Birthday-Instrumental.mp3" type="audio/mpeg"/>
</audio>
</html>
</html>

Explanation / Answer

Answer

Please save the file as <filename>.php . filename could be anything of your choice. Then run the aplication in apache server using xampp.

Also you need to change the logic for wishing the user "Today is your birthday". You need to compare today's date and today's month with his dob input. Please find the below modified code.

<!DOCTYPE html>
<html>
<head>
<title>Birthday</title>
   <link rel="stylesheet" type="text/css" href="styles.css">
   <h1>Is Today Your Birthday?!!</h1>
</head>
<body>

<?php

if(isset($_POST['sub']))

{

$mm=$_POST['mm'];

$dd=$_POST['dd'];

$yy=$_POST['yy'];

$dob=$mm ."/".$dd."/".$yy;

$arr=explode('/',$dob);

//$dateTs=date_default_timezone_set($dob);
$dateTs=strtotime($dob);

$now=strtotime('today');

if(sizeof($arr)!=3) die('ERROR:please entera valid date');

if(!checkdate($arr[0],$arr[1],$arr[2])) die('PLEASE: enter a valid dob');

if($dateTs>=$now) die('ENTER a dob earlier than today');

$ageDays=floor(($now-$dateTs)/86400);

$ageYears=floor($ageDays/365);

$ageMonths=floor(($ageDays-($ageYears*365))/30);

echo "<font color='red' size='10'> You are $ageYears years old. </font>";
if($mm==$now[0])
{
       echo "$dd";
       echo "$now[1]";
if($dd==$now[1]){
           echo"<br><font color='red' size='10'>Today is your birthday</font>";
       }
  
}
}

?>

<form method="post"><center>

Enter your DOB

<select name="yy">
<option value="">Year</option>
<?php
for($i=1899;$i<=2017;$i++)
{
  
   echo "<option value='".$i."'>".$i."</option>";

}
?>
</select>

<select name="mm">
<option value="">Month</option>
<?php
for($i=1;$i<=12;$i++)
{

echo "<option value='".$i."'>".$i."</option>";
}
?>
</select>

<select name="dd">
<option value="">Date</option>
<?php
for($i=1;$i<=31;$i++)
{
echo "<option value='".$i."'>".$i."</option>";
}

?>
</select>

<input type="submit" name="sub" value="check it"/>

</center>

</form>

</body>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<br>
<audio autoplay="" controls="">
<source src="Mira-Mira.mp3" type="audio/mpeg"/>
</audio>
</html>
</html>