I'm been looking for an answer to this but can't really find it. I have four Drop Down Menus with date and time info that I want to compile and update (or insert) into a Datetime column. Also, I'm kinda newbie at PHP and been relying on Dreamweaver for the update/insert functions. Here is how you do it. The trick is to replace GetSQLValueString($HTTP_POST_VARS['DateField'], "date")); in the Update area that Dreamweaver constructs with GetSQLValueString($Datetime, "date")); . I constructed the $Datetime a stupid way but it works.
<? require_once('Connections/MyConnection.php'); ?>
<?
$Y = $HTTP_POST_VARS['Year'];
$M = $HTTP_POST_VARS['Month'];
$D = $HTTP_POST_VARS['Day'];
$T = $HTTP_POST_VARS['Time'];
$S = "-";
$SS = " ";
$Datetime = $Y.$S.$M.$S.$D.$SS.$T;
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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}
if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE EManager SET Date=%s WHERE MNGID=%s",
GetSQLValueString($Datetime,"date"),
GetSQLValueString($HTTP_POST_VARS['MNGID'], "int"));
mysql_select_db($database_MyConnection, $MyConnection);
$Result1 = mysql_query($updateSQL, $MyConnection) or die(mysql_error());
$updateGoTo = "nextpage.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form action="<? echo $editFormAction; ?>" name="form1" method="POST">
<div align="center"> <br>
<select name="Month" id="select">
<option value='01'>January</option>
<option value='02'>February</option>
<option value='03'>March</option>
etc..
</select>
<select name="Day" id="Day">
<option value='01'>01</option>
<option value='02'>02</option>
<option value='03'>03</option>
etc..
</select>
<select name="Year" id="Year">
<option value='2004'>2004</option>
<option value='2005'>2005</option>
<option value='2006'>2006</option>
etc..
</select>
at
<select name="Time" id="Time">
<option value="18:00:00">6:00pm</option>
<option value="19:00:00">7:00pm</option>
<option value="20:00:00">8:00pm</option>
etc..
</select>
<br>
<input name="MNGID" type="hidden" id="MNGID" value="5">
<input name="Date" type="hidden" id="Date" value="<? echo $Datetime ?>">
<br>
<input type="submit" name="Submit" value="Submit">
</div>
<input type="hidden" name="MM_update" value="form1">
</form>
</body>
</html>