Hello,
I'm new to php and mysql and I use Dreamweaver MX 2004, so sorry for this
"newbie" question... I've found no answer in the forum ...
I've a date problem with my formular. In my mysql DB my filed "date" in
table "experience" is like this: Y-m-d (2002-07-23).
My fied`date` is date, NOT NULL with no default entry
My form read well the date data depending the id, (pe. 30.02.2003), but when
I submit a new date, I receive as result in the form "30.11.1999" and my DB
field I've now "0000-00-00"....
I don't know how to correct this... I've lost several hours and I think it's
simple...
I will appreciate any suggestion and help.
Thx for your time, regards,
Dominique
Here's the php code for my form:
<?php require_once('../../../Connections/metadeco_connect.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 != "") ? "'" . date("Y-d-m",strtotime($theValue)) .
"'" : "NULL";
break;
case "time":
$theValue = ($theValue != "") ? "'" . date("H:i:s",strtotime($theValue)) .
"'" : "NULL";
break;
case "datetime":
$theValue = ($theValue != "") ? "'" . date("Y-d-m
H:i:s",strtotime($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_update"])) && ($_POST["MM_update"] ==
"form_experience_edit")) {
$updateSQL = sprintf("UPDATE experience SET `date`=%s WHERE id=%s",
GetSQLValueString($_POST['datum'], "date"),
GetSQLValueString($_POST['hiddenField'], "int"));
mysql_select_db($database_metadeco_connect, $metadeco_connect);
$Result1 = mysql_query($updateSQL, $metadeco_connect) or die(mysql_error());
$updateGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
mysql_select_db($database_metadeco_connect, $metadeco_connect);
$query_rs1experience = "SELECT * FROM experience";
$rs1experience = mysql_query($query_rs1experience, $metadeco_connect) or
die(mysql_error());
$row_rs1experience = mysql_fetch_assoc($rs1experience);
$totalRows_rs1experience = mysql_num_rows($rs1experience);
// *** Move To Specific Record: declare variables
$MM_rs = &$rs1experience;
$row_MM_rs = &$row_rs1experience;
$MM_rsCount = $totalRows_rs1experience;
$MM_uniqueCol = "id";
$MM_paramName = "id";
$MM_paramIsDefined = ($MM_paramName != "" &&
isset($HTTP_GET_VARS[$MM_paramName]));
// *** Move To Specific Record: handle detail parameter
if ($MM_paramIsDefined && $MM_rsCount != 0) {
// get the value of the parameter
$param = $HTTP_GET_VARS[$MM_paramName];
// find the record with the unique column value equal to the parameter value
do {
if ($row_MM_rs[$MM_uniqueCol] == $param) break;
} while($row_MM_rs = mysql_fetch_assoc($MM_rs));
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Metadelic :: Portfolio Admin</title>
<link href="../../css/metastyle.css" rel="stylesheet" type="text/css">
</head>
<body>
<div align="center">
<form action="<?php echo $editFormAction; ?>" method="POST"
name="form_experience_edit" id="form_experience_edit">
<input name="hiddenField" type="hidden" value="<?php echo
$row_rs1experience['id']; ?>">
<table width="95%" border="0" cellspacing="5" cellpadding="3">
<tr>
<td align="right" valign="top" bgcolor="#eeeeee">Titre <strong>FR</strong>
</td>
<td width="100%" align="left" valign="top"> <span class="skills"><img
src="../images/arrowlink.gif" width="16" height="16" align="absmiddle"><?php
echo $row_rs1experience['titre_fr']; ?></span></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#eeeeee">Date</td>
<td align="left" valign="top">
<input name="datum" type="text" id="datum" value="<?php echo
date('Y.m.d',strtotime($row_rs1experience['date'])); ?>">
<br>
<img src="../images/arrowlink.gif" width="16" height="16"
align="absmiddle"><span class="skills"><?php echo date('d.m.Y',
strtotime($row_rs1experience['date']));?></span></td>
</tr>
<tr>
<td align="right" valign="top" bgcolor="#eeeeee">Confirmation</td>
<td align="left" valign="top"><input type="submit" name="Submit"
value="Valider">
<input name="Reset" type="reset" value="Reset"></td>
</tr>
</table>
<input type="hidden" name="MM_update" value="form_experience_edit">
</form> </div>
</body>
</html>
<?php
mysql_free_result($rs1experience);
?>