I have 3 text fields named "month, day, and year"
And 1 hidden field named "Date2"
My goal is to have the 3 fields combine to enter as date in Mysql.
I've tried this many different ways, the latest having the value of Date2 as <?php echo $year,'-', $month,'-', $day; ?>
Below is my complete code.
Any help to show me the proper way would be appreciated.
<?php require_once('Connections/MyHouse.php'); ?>
<?php
$year=$_POST['year'];
$month=$_POST['month'];
$day=$_POST['day'];
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO Bday (`Date`) VALUES (%s)",
GetSQLValueString($_POST['Date2'], "date"));
mysql_select_db($database_MyHouse, $MyHouse);
$Result1 = mysql_query($insertSQL, $MyHouse) or die(mysql_error());
}
mysql_select_db($database_MyHouse, $MyHouse);
$query_Recordset1 = "SELECT bdayid, `Date`, `day`, `month`, `year` FROM Bday";
$Recordset1 = mysql_query($query_Recordset1, $OrchardHouse) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?><!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>
<form action="<?php echo $editFormAction; ?>" id="form1" name="form1" method="POST">
<table width="800" border="0">
<tr>
<td>date</td>
<td><label>
<input name="month" type="text" id="month" size="2" maxlength="2" />
/
<input name="day" type="text" id="day" size="2" maxlength="2" />
/
<input name="year" type="text" id="year" size="4" maxlength="4" />
</label></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
<tr>
<td><input name="Date2" type="hidden" id="Date2" value="<?php echo $year,'-', $month,'-', $day; ?>" /></td>
<td><label>
<input type="submit" name="submit" id="submit" value="Submit" />
</label></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form1" />
</form>
<?php
echo $year,'-', $month,'-', $day; ?>
<?php echo $Date2
?>
</body>
</html>
<?php
mysql_free_result($Recordset1);
?>