Forums
This topic is locked
Inserting date
Posted 31 Jul 2001 15:30:55
1
has voted
31 Jul 2001 15:30:55 Keith Slater posted:
time to start up the questions again... When some one submits a form I want it to submit the date to the database.. is their a line I could put in a hidden field or is their an easier solution?? thanks
Keith Slater
Word Pro Systems
www.wordprosys.com
Replies
Replied 31 Jul 2001 16:08:30
31 Jul 2001 16:08:30 Tim Green replied:
The cross-database solution is this :-
Insert into your form a hidden field like this :-
<input type="hidden" name="myDate" value="<?php echo date("m/d/Y" ?>">
Then in your source code, just below the 'require' statements block, add the code :-
<?php
if (isset($myDate)) {
$myDate=$connectionName->DBDate($myDate);
}
?>
The standard insert record behaviour should actually be able to cope with this, but unfortunately it looks like that area of code hasn't been implemented.
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Insert into your form a hidden field like this :-
<input type="hidden" name="myDate" value="<?php echo date("m/d/Y" ?>">
Then in your source code, just below the 'require' statements block, add the code :-
<?php
if (isset($myDate)) {
$myDate=$connectionName->DBDate($myDate);
}
?>
The standard insert record behaviour should actually be able to cope with this, but unfortunately it looks like that area of code hasn't been implemented.
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 31 Jul 2001 16:11:31
31 Jul 2001 16:11:31 Keith Slater replied:
Replied 31 Jul 2001 16:30:13
31 Jul 2001 16:30:13 Tim Green replied:
I should, of course, have specified also, that the Database Column should be set to the correct Field type. (DATE in MySQL, or Date/Time in Access).
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 31 Jul 2001 16:31:19
31 Jul 2001 16:31:19 Keith Slater replied:
Replied 02 Aug 2001 18:03:06
02 Aug 2001 18:03:06 Keith Slater replied:
when u set up the database field to date/time do I have to set up the insert form to submit it as a date? I've tried that and I still cant get it to insert right... I get this error
[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
and I know it means its having probems inserting something into my database and the only thing I can figure is the date thing.... thanks again
Keith Slater
Word Pro Systems
www.wordprosys.com
[Microsoft][ODBC Microsoft Access Driver] Syntax error in INSERT INTO statement.
and I know it means its having probems inserting something into my database and the only thing I can figure is the date thing.... thanks again
Keith Slater
Word Pro Systems
www.wordprosys.com
Replied 03 Aug 2001 00:08:15
03 Aug 2001 00:08:15 Tim Green replied:
As my earlier post said, the standard insert behaviour *should* be able to cope with this, but it unfortunately seems not to be implemented yet in PHAkT.
It should work just leaving the field set as text. The $myDate=$connectionName->DBDate($myDate) part of the code *should* format the date correctly for the db.
This is all untested you understand, as I don't use Access in a production environment. Though these techniques work within MySQL using the ADODB wrapper library and *should* therefore be cross-database.....
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
It should work just leaving the field set as text. The $myDate=$connectionName->DBDate($myDate) part of the code *should* format the date correctly for the db.
This is all untested you understand, as I don't use Access in a production environment. Though these techniques work within MySQL using the ADODB wrapper library and *should* therefore be cross-database.....
Tim Green
Extension & PHP TalkZone Manager
<font size=1>-------------------------------------------
<i>Please read the Forum FAQ before posting
a question to this TalkZone.</i>
-------------------------------------------
www.UDzone.com : A dynamic Dreamweaver,
Ultradev and Fireworks site for developers
by developers.
-------------------------------------------</font id=size1>
Replied 30 Sep 2001 01:58:51
30 Sep 2001 01:58:51 dyna c replied:
I tried the fix, and set the MYSQL date Field to text but i get a error "You have an error in your SQL syntax near '1970-01-01'')' at line 1" Can you let me know where iam going wrong - thanks
here is the code
<?php
// Copyright (c) Interakt Online 2001
// www.interakt.ro/
require("./../../adodb/adodb.inc.php"
require("./../../Connections/joblist.php"
?><?php
if (isset($myDate)) {
$myDate=$joblist->DBDate($myDate);
}
?><?php
// *** Edit Operations: declare Tables
$MM_editAction = $PHP_SELF;
if ($QUERY_STRING) {
$MM_editAction = $MM_editAction . "?" . $QUERY_STRING;
}
$MM_abortEdit = 0;
$MM_editQuery = "";
?>
<?php
// *** Insert Record: set Variables
if (isset($MM_insert)){
// $MM_editConnection = MM_joblist_STRING;
$MM_editTable = "recurit_job";
$MM_editRedirectUrl = "";
$MM_fieldsStr = "job_ref|value|job_title|value|job_bus_area|value|job_duration|value|job_salary|value|job_location|value|job_description|value|Job_hot|value|job_id|value|myDate|value";
$MM_columnsStr = "job_ref|',none,''|job_title|',none,''|job_bus_area|',none,''|job_duration|',none,''|job_salary|',none,''|job_location|',none,''|job_description|',none,''|job_hot|none,'Y','N'|job_id|none,none,NULL|job_time|',none,NULL";
// create the $MM_fields and $MM_columns arrays
$MM_fields = explode("|", $MM_fieldsStr);
$MM_columns = explode("|", $MM_columnsStr);
// set the form values
for ($i=0; $i+1 < sizeof($MM_fields); ($i=$i+2)) {
$MM_fields[$i+1] = $$MM_fields[$i];
}
// append the query string to the redirect URL
if ($MM_editRedirectUrl && $QUERY_STRING && (strlen($QUERY_STRING) > 0)) {
$MM_editRedirectUrl .= ((strpos($MM_editRedirectUrl, '?') == false)?"?":"&" . $QUERY_STRING;
}
}
?>
<?php
// *** Insert Record: construct a sql insert statement and execute it
if (isset($MM_insert)) {
// create the sql insert statement
$MM_tableValues = "";
$MM_dbValues = "";
for ( $i=0; $i+1 < sizeof($MM_fields); ($i=$i+2)) {
$formVal = $MM_fields[$i+1];
$MM_typesArray = explode(",", $MM_columns[$i+1]);
$delim = $MM_typesArray[0];
if($delim=="none" $delim="";
$altVal = $MM_typesArray[1];
if($altVal=="none" $altVal="";
$emptyVal = $MM_typesArray[2];
if($emptyVal=="none" $emptyVal="";
if ($formVal == "" || !isset($formVal)) {
$formVal = $emptyVal;
}
else {
if ($altVal != "" {
$formVal = $altVal;
}
else if ($delim == "'" { // escape quotes
$formVal = $delim . $formVal . $delim;
//$formVal = "'" . str_replace("'","\'",$formVal) . "'";
}
else {
$formVal = $delim . $formVal . $delim;
}
}
if ($i == 0) {
$MM_tableValues = $MM_tableValues . $MM_columns[$i];
$MM_dbValues = $MM_dbValues . $formVal;
}
else {
$MM_tableValues = $MM_tableValues . "," . $MM_columns[$i];
$MM_dbValues = $MM_dbValues . "," . $formVal;
}
}
$MM_editQuery = "insert into " . $MM_editTable . " (" . $MM_tableValues . " values (" . $MM_dbValues . "";
if ($MM_abortEdit!=1) {
// execute the insert
$queryrs = $joblist->Execute($MM_editQuery) or DIE($joblist->ErrorMsg());
if ($MM_editRedirectUrl) {
header ("Location: $MM_editRedirectUrl"
}
}
}
?><?php
?>
<html>
<head>
<title>Job Insert</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table cellspacing=1 cellpadding=5 width="100%" border=0 bgcolor="#000000">
<tr bgcolor=#98CCC8>
<td align="left"><font face="Arial, Helvetica, sans-serif"
size=3 color="#003366"><b><i>CREATE NEW JOB</i></b></font> </td>
</tr>
</table>
<form ACTION="<?php echo $MM_editAction?>" METHOD="POST" name="InsertForm">
<table align="center" width="100%" cellspacing="1" bordercolor="#000000" border="0" cellpadding="1" bgcolor="#000000">
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF">Job Ref:</td>
<td bgcolor="#FFFFFF">
<input type="text" name="job_ref" size="32" >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF">Title:</td>
<td bgcolor="#FFFFFF">
<input type="text" name="job_title" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF">Industry:</td>
<td bgcolor="#FFFFFF">
<select name="select" size="1">
<option value="NO INDUSTRY">Please Select</option>
</select>
</td>
</tr>
<tr valign="baseline" bgcolor="#FFFFFF">
<td nowrap align="right" bgcolor="#FFFFFF">Business Area:</td>
<td>
<input type="text" name="job_bus_area" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF">Duration:</td>
<td bgcolor="#FFFFFF">
<input type="text" name="job_duration" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF"> Salary:</td>
<td bgcolor="#FFFFFF">
<input type="text" name="job_salary" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF">Location:</td>
<td bgcolor="#FFFFFF">
<input type="text" name="job_location" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF"> Contact Email:</td>
<td bgcolor="#FFFFFF">
<select name="email" size="1">
<option value="NO EMAIL ADDRESS">Please Select</option>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top" bgcolor="#FFFFFF">Description:</td>
<td bgcolor="#FFFFFF">
<textarea name="job_description" cols="60" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF">Hot Job (check):</td>
<td bgcolor="#FFFFFF">
<input type="checkbox" name="Job_hot" value="checkbox">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#98CCC8"> </td>
<td bgcolor="#98CCC8">
<input type="submit" name="Insert Record" value="Insert Record">
</td>
</tr>
</table>
<input type="hidden" name="job_id">
<input type="hidden" name="myDate" value="<?php echo date("m/d/Y" ?>">
<input type="hidden" name="MM_insert" value="true">
</form>
<p> </p>
</body>
</html>
here is the code -
here is the code
<?php
// Copyright (c) Interakt Online 2001
// www.interakt.ro/
require("./../../adodb/adodb.inc.php"
require("./../../Connections/joblist.php"
?><?php
if (isset($myDate)) {
$myDate=$joblist->DBDate($myDate);
}
?><?php
// *** Edit Operations: declare Tables
$MM_editAction = $PHP_SELF;
if ($QUERY_STRING) {
$MM_editAction = $MM_editAction . "?" . $QUERY_STRING;
}
$MM_abortEdit = 0;
$MM_editQuery = "";
?>
<?php
// *** Insert Record: set Variables
if (isset($MM_insert)){
// $MM_editConnection = MM_joblist_STRING;
$MM_editTable = "recurit_job";
$MM_editRedirectUrl = "";
$MM_fieldsStr = "job_ref|value|job_title|value|job_bus_area|value|job_duration|value|job_salary|value|job_location|value|job_description|value|Job_hot|value|job_id|value|myDate|value";
$MM_columnsStr = "job_ref|',none,''|job_title|',none,''|job_bus_area|',none,''|job_duration|',none,''|job_salary|',none,''|job_location|',none,''|job_description|',none,''|job_hot|none,'Y','N'|job_id|none,none,NULL|job_time|',none,NULL";
// create the $MM_fields and $MM_columns arrays
$MM_fields = explode("|", $MM_fieldsStr);
$MM_columns = explode("|", $MM_columnsStr);
// set the form values
for ($i=0; $i+1 < sizeof($MM_fields); ($i=$i+2)) {
$MM_fields[$i+1] = $$MM_fields[$i];
}
// append the query string to the redirect URL
if ($MM_editRedirectUrl && $QUERY_STRING && (strlen($QUERY_STRING) > 0)) {
$MM_editRedirectUrl .= ((strpos($MM_editRedirectUrl, '?') == false)?"?":"&" . $QUERY_STRING;
}
}
?>
<?php
// *** Insert Record: construct a sql insert statement and execute it
if (isset($MM_insert)) {
// create the sql insert statement
$MM_tableValues = "";
$MM_dbValues = "";
for ( $i=0; $i+1 < sizeof($MM_fields); ($i=$i+2)) {
$formVal = $MM_fields[$i+1];
$MM_typesArray = explode(",", $MM_columns[$i+1]);
$delim = $MM_typesArray[0];
if($delim=="none" $delim="";
$altVal = $MM_typesArray[1];
if($altVal=="none" $altVal="";
$emptyVal = $MM_typesArray[2];
if($emptyVal=="none" $emptyVal="";
if ($formVal == "" || !isset($formVal)) {
$formVal = $emptyVal;
}
else {
if ($altVal != "" {
$formVal = $altVal;
}
else if ($delim == "'" { // escape quotes
$formVal = $delim . $formVal . $delim;
//$formVal = "'" . str_replace("'","\'",$formVal) . "'";
}
else {
$formVal = $delim . $formVal . $delim;
}
}
if ($i == 0) {
$MM_tableValues = $MM_tableValues . $MM_columns[$i];
$MM_dbValues = $MM_dbValues . $formVal;
}
else {
$MM_tableValues = $MM_tableValues . "," . $MM_columns[$i];
$MM_dbValues = $MM_dbValues . "," . $formVal;
}
}
$MM_editQuery = "insert into " . $MM_editTable . " (" . $MM_tableValues . " values (" . $MM_dbValues . "";
if ($MM_abortEdit!=1) {
// execute the insert
$queryrs = $joblist->Execute($MM_editQuery) or DIE($joblist->ErrorMsg());
if ($MM_editRedirectUrl) {
header ("Location: $MM_editRedirectUrl"
}
}
}
?><?php
?>
<html>
<head>
<title>Job Insert</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table cellspacing=1 cellpadding=5 width="100%" border=0 bgcolor="#000000">
<tr bgcolor=#98CCC8>
<td align="left"><font face="Arial, Helvetica, sans-serif"
size=3 color="#003366"><b><i>CREATE NEW JOB</i></b></font> </td>
</tr>
</table>
<form ACTION="<?php echo $MM_editAction?>" METHOD="POST" name="InsertForm">
<table align="center" width="100%" cellspacing="1" bordercolor="#000000" border="0" cellpadding="1" bgcolor="#000000">
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF">Job Ref:</td>
<td bgcolor="#FFFFFF">
<input type="text" name="job_ref" size="32" >
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF">Title:</td>
<td bgcolor="#FFFFFF">
<input type="text" name="job_title" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF">Industry:</td>
<td bgcolor="#FFFFFF">
<select name="select" size="1">
<option value="NO INDUSTRY">Please Select</option>
</select>
</td>
</tr>
<tr valign="baseline" bgcolor="#FFFFFF">
<td nowrap align="right" bgcolor="#FFFFFF">Business Area:</td>
<td>
<input type="text" name="job_bus_area" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF">Duration:</td>
<td bgcolor="#FFFFFF">
<input type="text" name="job_duration" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF"> Salary:</td>
<td bgcolor="#FFFFFF">
<input type="text" name="job_salary" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF">Location:</td>
<td bgcolor="#FFFFFF">
<input type="text" name="job_location" size="32">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF"> Contact Email:</td>
<td bgcolor="#FFFFFF">
<select name="email" size="1">
<option value="NO EMAIL ADDRESS">Please Select</option>
</select>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" valign="top" bgcolor="#FFFFFF">Description:</td>
<td bgcolor="#FFFFFF">
<textarea name="job_description" cols="60" rows="5"></textarea>
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#FFFFFF">Hot Job (check):</td>
<td bgcolor="#FFFFFF">
<input type="checkbox" name="Job_hot" value="checkbox">
</td>
</tr>
<tr valign="baseline">
<td nowrap align="right" bgcolor="#98CCC8"> </td>
<td bgcolor="#98CCC8">
<input type="submit" name="Insert Record" value="Insert Record">
</td>
</tr>
</table>
<input type="hidden" name="job_id">
<input type="hidden" name="myDate" value="<?php echo date("m/d/Y" ?>">
<input type="hidden" name="MM_insert" value="true">
</form>
<p> </p>
</body>
</html>
here is the code -