Current location: Hot Scripts Forums » Programming Languages » PHP » Problem with date and form


Problem with date and form

Reply
  #1 (permalink)  
Old 04-30-04, 07:46 AM
djavet djavet is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Problem with date and form

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('d.m.Y',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">
&nbsp;&nbsp;
<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);
?>

Last edited by djavet; 04-30-04 at 07:49 AM.
Reply With Quote
  #2 (permalink)  
Old 04-30-04, 08:34 AM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
you were passing the date in this format d.m.Y !!
just use mysql's format,
change this:
Code:
<input name="datum" type="text" id="datum" value="<?php echo date('d.m.Y',strtotime($row_rs1experience['date'])); ?>">
to this:
Code:
<input name="datum" type="text" id="datum" value="<?php echo date('Y-m-d',strtotime($row_rs1experience['date'])); ?>">
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Reply With Quote
  #3 (permalink)  
Old 04-30-04, 08:58 AM
djavet djavet is offline
Newbie Coder
 
Join Date: Apr 2004
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Hummm thx, but I've try this also with no success.
Same problem...

....

Dom
Reply With Quote
  #4 (permalink)  
Old 05-02-04, 12:37 AM
Merovingian's Avatar
Merovingian Merovingian is offline
Newbie Coder
 
Join Date: Jan 2004
Location: Los Angeles
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
LOL I posted this question a long time ago.

define the day with a variable as so:
PHP Code:

$today date("Y-m-d H:i:s"); 

It worked for me perfectly.
Btw youll need to insert that into the database then retrieve it using something like:
PHP Code:

echo $row['date']; 

Enjoy... >:O
__________________
"Duo seguere aut de via decede" ...
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Newbie found a solution to a date problem. mickey_kamer Perl 4 05-09-07 05:54 AM
formmail problem gscraper Perl 12 08-27-04 03:06 AM
How do I get line breaks to carry over from form to database? Poodle Tosser PHP 3 03-31-04 07:50 AM
help regarding insertion of date time wajeeh_r ASP 1 03-04-04 04:05 PM
Problem with date in combobox. Periodically lose valu Danie Visual Basic 1 03-04-04 02:41 PM


All times are GMT -5. The time now is 10:31 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.