At the moment the date is displayed as dd-MM-yyyy but of course this won't add to the mysql database, if I change the display to yyyy-MM-dd then it displays in that format (which I don't want) but will add to the database OK.
I had thought that I could change one of these sections (quoted below) to reformat the date but whatever I tried just failed, I am posting here as it may be something I need to change in the Javascript rather than the PHP/MYSQL parts.
Thanks for any help offered.
Gordon
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
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"));
Full Code:
[PHP]
<?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());
}
[/PHP]
?><!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" />
[CODE-JAVASCRIPT]
<SCRIPT LANGUAGE="JavaScript" SRC="/CalendarPopup.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript">
var cal = new CalendarPopup();
</SCRIPT>
[/code]
<title>Untitled Document</title>
</head>
[CODE-HTML]
<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', 'dd-MM-yyyy'); 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>
[/code]