I have been trying my best to display a chosen date as dd-mm-yyyy but insert it into the mysql database as yyyy-mm-dd, I know it must be simple but no matter what I try I can't get it to work.
Code:
<?php require_once('../Connections/wind.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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 readings (windyboy, white, `date`, meter) VALUES (%s, %s, %s, %s)",
GetSQLValueString($_POST['windyboy'], "int"),
GetSQLValueString($_POST['white'], "int"),
GetSQLValueString($_POST['date'], "date"),
GetSQLValueString($_POST['meter'], "int"));
mysql_select_db($database_wind, $wind);
$Result1 = mysql_query($insertSQL, $wind) or die(mysql_error());
}
?><!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=iso-8859-1" />
<SCRIPT LANGUAGE="JavaScript" SRC="/CalendarPopup.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
var cal = new CalendarPopup();
</SCRIPT>
<title>Untitled Document</title>
</head>
<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
<p>windyboy
<input name="windyboy" type="text" id="windyboy" />
</p>
<p>white
<input name="white" type="text" id="white" />
</p>
<p>date
<input name="date" type="date" id="date" />
<A HREF="#"
onClick="cal.select(document.form1.date,'anchor1', 'yyyy-MM-dd'); return false;"
NAME="anchor1" ID="anchor1">select</A>
</p>
<p>meter
<input name="meter" type="text" id="meter" />
</p>
<input type="hidden" name="MM_insert" value="form1">
submit
<input type="submit" name="Submit" value="Submit" />
<input type="hidden" name="hiddenField" />
</form>
</body>
</html>