<?php
require_once $_SERVER['DOCUMENT_ROOT'] . 'classes/DatabaseManager.php';
$conn = DatabaseManager::getConnection();
require_once('utility_funcs.inc.php');
$dateOfBirth = convertDateToMySQL($_POST['month'], $_POST['day'], $_POST['year']);
$weddingAnniversaryDate = convertDateToMySQL($_POST['month'], $_POST['day'], $_POST['year']);
$wifeDateOfBirth = convertDateToMySQL($_POST['month'], $_POST['day'], $_POST['year']);
// $purchaseDate is now an array
// temp line of debug
// var_dump($purchaseDate) ; // inspect it
if(isset($_POST['submit']) && $_POST['submit'] == 'Submit')
{
$sql = "INSERT INTO mydate (firstName, lastName, dateOfBirth, weddingAnniversaryDate, wifeDateOfBirth) VALUES

firstName, :lastName, :dateOfBirth, :weddingAnniversaryDate, :wifeDateOfBirth)";
try
{
$st->bindParam( ":firstname", $_POST['firstname'], PDO::PARAM_STR );
$st->bindParam( ":lastname", $_POST['lastname'], PDO::PARAM_STR );
if($dateOfBirth[0] === true){
// go ahead and try and insert it into the db
$st = $conn->prepare ( $sql );
$st->bindParam( ":dateOfBirth", $dateOfBirth[1]);
}
else
{
echo "Warning: $dateOfBirth[1]" ;
}
if($weddingAnniversaryDate[0] === true){
// go ahead and try and insert it into the db
$st = $conn->prepare ( $sql );
$st->bindParam( ":weddingAnniversaryDate", $weddingAnniversaryDate[1]);
}
else
{
echo "Warning: $weddingAnniversaryDate[1]" ;
}
if($wifeDateOfBirth[0] === true){
// go ahead and try and insert it into the db
$st = $conn->prepare ( $sql );
$st->bindParam( ":wifeDateOfBirth", $wifeDateOfBirth[1]);
}
else
{
echo "Warning: $wifeDateOfBirth[1]" ;
}
$st->execute();
$conn = null;
}
catch(PDOException $e)
{
echo 'Unable to insert info into the database' . $e->getMessage();
exit();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="600" border="0" align="center" cellpadding="2" cellspacing="5">
<form id="form1" method="post" action="">
<tr>
<td width="30%" align="right" valign="middle">Lastname

/td>
<td width="70%"><input name="lastName" type="text" id="lastName" /></td>
</tr>
<tr>
<td width="30%" align="right" valign="middle">Firstname

/td>
<td width="70%"><input name="firstName" type="text" id="firstName" /></td>
</tr>
<tr>
<td width="30%" align="right" valign="middle">Date of Birth

/td>
<td width="70%">
<label for="select">Month

/label>
<select name="month" id="month">
<option value="">Select</option>
<option value="1" <?php if(isset($month) && $month == '1') echo 'selected'; ?> >Jan</option>
<option value="2" <?php if(isset($month) && $month == '2') echo 'selected'; ?> >Feb</option>
<option value="3" <?php if(isset($month) && $month == '3') echo 'selected'; ?> >Mar</option>
<option value="4" <?php if(isset($month) && $month == '4') echo 'selected'; ?> >Apr</option>
<option value="5" <?php if(isset($month) && $month == '5') echo 'selected'; ?> >May</option>
<option value="6" <?php if(isset($month) && $month == '6') echo 'selected'; ?> >Jun</option>
<option value="7" <?php if(isset($month) && $month == '7') echo 'selected'; ?> >Jul</option>
<option value="8" <?php if(isset($month) && $month == '8') echo 'selected'; ?> >Aug</option>
<option value="9" <?php if(isset($month) && $month == '9') echo 'selected'; ?> >Sep</option>
<option value="10" <?php if(isset($month) && $month == '10') echo 'selected'; ?> >Oct</option>
<option value="11" <?php if(isset($month) && $month == '11') echo 'selected'; ?> >Nov</option>
<option value="12" <?php if(isset($month) && $month == '12') echo 'selected'; ?> >Dec</option>
</select>
<label for="day">Date

/label>
<?php
$dates = range(1,31); // create an array of numbers 1-31
$match = 3 ;
echo "<select id=day name=day >" . PHP_EOL ;
foreach ($dates as $date){ // iterate (loop) through the array
$selected = ($date === $match) ? "selected=selected" : "" ;
// same as writing : if this date matches the chosen date, make it selected else echo empty string
echo "<option = $date $selected>$date</option>" . PHP_EOL ;
}
echo "</select>" . PHP_EOL ;
?>
<label for="year">Year

/label>
<input name="year" type="number" required id="year" maxlength="4" placeholder="YYYY" value="<?php if(isset($year)) echo $year; ?>"></td>
</tr>
<tr>
<td width="30%" align="right" valign="middle">Wedding Anniversary Date

/td>
<td width="70%">
<label for="select">Month

/label>
<select name="month" id="month">
<option value="">Select</option>
<option value="1" <?php if(isset($month) && $month == '1') echo 'selected'; ?> >Jan</option>
<option value="2" <?php if(isset($month) && $month == '2') echo 'selected'; ?> >Feb</option>
<option value="3" <?php if(isset($month) && $month == '3') echo 'selected'; ?> >Mar</option>
<option value="4" <?php if(isset($month) && $month == '4') echo 'selected'; ?> >Apr</option>
<option value="5" <?php if(isset($month) && $month == '5') echo 'selected'; ?> >May</option>
<option value="6" <?php if(isset($month) && $month == '6') echo 'selected'; ?> >Jun</option>
<option value="7" <?php if(isset($month) && $month == '7') echo 'selected'; ?> >Jul</option>
<option value="8" <?php if(isset($month) && $month == '8') echo 'selected'; ?> >Aug</option>
<option value="9" <?php if(isset($month) && $month == '9') echo 'selected'; ?> >Sep</option>
<option value="10" <?php if(isset($month) && $month == '10') echo 'selected'; ?> >Oct</option>
<option value="11" <?php if(isset($month) && $month == '11') echo 'selected'; ?> >Nov</option>
<option value="12" <?php if(isset($month) && $month == '12') echo 'selected'; ?> >Dec</option>
</select>
<label for="day">Date

/label>
<?php
$dates = range(1,31); // create an array of numbers 1-31
$match = 3 ;
echo "<select id=day name=day >" . PHP_EOL ;
foreach ($dates as $date){ // iterate (loop) through the array
$selected = ($date === $match) ? "selected=selected" : "" ;
// same as writing : if this date matches the chosen date, make it selected else echo empty string
echo "<option = $date $selected>$date</option>" . PHP_EOL ;
}
echo "</select>" . PHP_EOL ;
?>
<label for="year">Year

/label>
<input name="year" type="number" required id="year" maxlength="4" placeholder="YYYY" value="<?php if(isset($year)) echo $year; ?>"></td>
</tr>
<tr>
<td width="30%" align="right" valign="middle">Wife's Date of Birth

/td>
<td width="70%">
<label for="select">Month

/label>
<select name="month" id="month">
<option value="">Select</option>
<option value="1" <?php if(isset($month) && $month == '1') echo 'selected'; ?> >Jan</option>
<option value="2" <?php if(isset($month) && $month == '2') echo 'selected'; ?> >Feb</option>
<option value="3" <?php if(isset($month) && $month == '3') echo 'selected'; ?> >Mar</option>
<option value="4" <?php if(isset($month) && $month == '4') echo 'selected'; ?> >Apr</option>
<option value="5" <?php if(isset($month) && $month == '5') echo 'selected'; ?> >May</option>
<option value="6" <?php if(isset($month) && $month == '6') echo 'selected'; ?> >Jun</option>
<option value="7" <?php if(isset($month) && $month == '7') echo 'selected'; ?> >Jul</option>
<option value="8" <?php if(isset($month) && $month == '8') echo 'selected'; ?> >Aug</option>
<option value="9" <?php if(isset($month) && $month == '9') echo 'selected'; ?> >Sep</option>
<option value="10" <?php if(isset($month) && $month == '10') echo 'selected'; ?> >Oct</option>
<option value="11" <?php if(isset($month) && $month == '11') echo 'selected'; ?> >Nov</option>
<option value="12" <?php if(isset($month) && $month == '12') echo 'selected'; ?> >Dec</option>
</select>
<label for="day">Date

/label>
<?php
$dates = range(1,31); // create an array of numbers 1-31
$match = 3 ;
echo "<select id=day name=day >" . PHP_EOL ;
foreach ($dates as $date){ // iterate (loop) through the array
$selected = ($date === $match) ? "selected=selected" : "" ;
// same as writing : if this date matches the chosen date, make it selected else echo empty string
echo "<option = $date $selected>$date</option>" . PHP_EOL ;
}
echo "</select>" . PHP_EOL ;
?>
<label for="year">Year

/label>
<input name="year" type="number" required id="year" maxlength="4" placeholder="YYYY" value="<?php if(isset($year)) echo $year; ?>"></td>
</tr>
<tr>
<td colspan="2" align="center" valign="middle"><input type="submit" name="submit" id="submit" value="Submit" /></td>
</tr>
</form>
</table>
</body>
</html>
Bookmarks