datepicker + php insert
Hello all I/ve browsed the forums & either can t find o runderstand the answers.
Trying to use date picker with an insert record form& am gettting the following error
Notice: Undefined index: ReadDate in C:\xampp\htdocs\solar\readings.php on line 42
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
My DW code is
<?php require_once('Connections/con_solar.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$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 daily (ID, ReadDate, accountno, Tarr11, Tarr33, Export, SolarDay) VALUES (%s, #datepicker, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['ID'], "int"),
GetSQLValueString($_POST['ReadDate'], "date"),
GetSQLValueString($_POST['accountno'], "int"),
GetSQLValueString($_POST['Tarr11'], "int"),
GetSQLValueString($_POST['Tarr33'], "int"),
GetSQLValueString($_POST['Export'], "int"),
GetSQLValueString($_POST['SolarDay'], "int"));
mysql_select_db($database_con_solar, $con_solar);
$Result1 = mysql_query($insertSQL, $con_solar) or die(mysql_error());
$insertGoTo = "results.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
mysql_select_db($database_con_solar, $con_solar);
$query_readings = "SELECT * FROM daily";
$readings = mysql_query($query_readings, $con_solar) or die(mysql_error());
$row_readings = mysql_fetch_assoc($readings);
$totalRows_readings = mysql_num_rows($readings);
?>
<!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>Solar daily readings</title>
<style type="text/css">
body,td,th {
color: #000;
}
body {
background-color: #FC3;
}
</style>
<script src="jquery-ui-1.7.2/js/jquery-1.3.2.min.js" type="text/javascript"></script>
<script src="jquery-ui-1.7.2/js/jquery-ui-1.7.2.min.js" type="text/javascript"></script>
<link href="jquery-ui-1.7.2/css/base/ui.core.css" rel="stylesheet" type="text/css" />
<link href="jquery-ui-1.7.2/css/base/ui.datepicker.css" rel="stylesheet" type="text/css" />
<link href="jquery-ui-1.7.2/css/base/ui.theme.css" rel="stylesheet" type="text/css" />
<link href="jquery-ui-1.7.2/css/base/ui.datepicker.images.css" rel="stylesheet" type="text/css" />
<style type="text/css">
/* BeginOAWidget_Instance_2137022: #datepicker */
#datepicker .ui-widget {
font-family: inherit;
}
#datepicker .ui-datepicker {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
}
#datepicker .ui-datepicker-title {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
font-size: 1.1em;
color: #cc0000;
font-weight: normal;
line-height: 1.8em;
}
#datepicker .ui-state-default, .ui-widget-content .ui-state-default {
border-color: #ff9900;
background-color: #ff9900;
color: #cc0000;
}
#datepicker .ui-state-default, .ui-state-default a {
color: #cc0000;
}
#datepicker .ui-state-highlight, .ui-widget-content .ui-state-highlight {
border-color:#66cc99;
background-color:#66cc99;
color:#666699;
}
#datepicker .ui-state-active, .ui-widget-content .ui-state-active {
border-color: #333399;
background-color: #333399;
color: #330066;
}
#datepicker .ui-state-hover, .ui-widget-content .ui-state-hover, .ui-state-focus, .ui-widget-content .ui-state-focus
{
border-color: #ffff99;
background-color: #ffff99;
color: #ff3300;
}
#datepicker .ui-widget-header
{
border-color: #cc0000;
background-color: #ff9900;
border-width: 2px;
}
/* Text attributes for the Days of Week Text */
#datepicker .ui-datepicker table th
{
font-size: .8em;
color: #cc0000;
font-weight: bold;
}
/* EndOAWidget_Instance_2137022 */
</style>
<script type="text/xml">
<!--
<oa:widgets>
<oa:widget wid="2137022" binding="#datepicker" />
</oa:widgets>
-->
</script>
</head>
<body>
<form action="<?php echo $editFormAction; ?>" method="post" name="form1" id="form1">
<table align="center">
<tr valign="baseline">
<td nowrap="nowrap" align="right">ID:</td>
<td><input type="text" name="ID" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">ReadDate:</td>
<td><script type="text/javascript">
// BeginOAWidget_Instance_2137022: #datepicker
$(function() {
$("#ReadDate").datepicker({ showOtherMonths: true });
$( ".selector" ).datepicker( "option", "dateFormat", "dd-mm-yy" );
});
// EndOAWidget_Instance_2137022
</script>
<input type="text" id="ReadDate" value=""></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Accountno:</td>
<td><input type="text" name="accountno" value="13351887" size="20" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Tarr11:</td>
<td><input type="text" name="Tarr11" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Tarr33:</td>
<td><input type="text" name="Tarr33" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">Export:</td>
<td><input type="text" name="Export" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right">SolarDay:</td>
<td><input type="text" name="SolarDay" value="" size="32" /></td>
</tr>
<tr valign="baseline">
<td nowrap="nowrap" align="right"> </td>
<td><input type="submit" value="Insert record" /></td>
</tr>
</table>
<p>
<input type="hidden" name="MM_insert" value="form1" />
</p>
<p> </p>
<p> </p>
<p><div class="demo">
<p>Date: <input type="text" id="datepicker"></p>
</div><!-- End demo --></p>
</form>
<p> </p>
</body>
</html>
<?php
mysql_free_result($readings);
?>