PHP wizards one an all,
I need help with some PHP syntax (maybe a system memory variable too).
I would like to know how to insert the current system date into a MySQL column.
Below is some code generated from Dreamweaver that inserts a date provided via an input form. I would like to replace the form's input value and simply insert the date behind the scenes (no need to ask the user to supply today's date) I believe the date format MySQL expects is YYYY-MM-DD.
Now that I think about it, it would be nice to know the same thing for a column defined as a timestamp as well.
Thanks ahead of time for any time you can devote to my inquiry.
*********************************************
______________the infamous CODE_______________
*********************************************
<?php require_once('Connections/test.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 SUBSCRIBER_T (FULL_NAME, EMAIL_ADDR, CREATE_DT) VALUES (%s, %s, %s)",
GetSQLValueString($_POST['FULL_NAME'], "text"),
GetSQLValueString($_POST['EMAIL_ADDR'], "text"),
GetSQLValueString($_POST['CREATE_DT'], "date"));
mysql_select_db($database_test, $test);
$Result1 = mysql_query($insertSQL, $test) or die(mysql_error());
}
?>