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: 3817995 • 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

The Problem to your code is as below:

When a given HTML file contains PHP code,you need to configure the .htaccess file to read the PHP code in the HTML file without renaming it or changing its extension. Below you can view the "handlers", which will have to be added:

AddHandler cgi-script .html .htm

Then try to run the .html code of your to ensure that the php code is read after clicking on the button.