Forums

PHP

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>
Replied 31 Jul 2001 16:11:31
31 Jul 2001 16:11:31 Keith Slater replied:
ah thanks again

Keith Slater
Word Pro Systems
www.wordprosys.com
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>
Replied 31 Jul 2001 16:31:19
31 Jul 2001 16:31:19 Keith Slater replied:
makes sense

Keith Slater
Word Pro Systems
www.wordprosys.com
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
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-&gt;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
&lt;?php


// Copyright (c) Interakt Online 2001
// www.interakt.ro/

require("./../../adodb/adodb.inc.php";
require("./../../Connections/joblist.php";
?&gt;&lt;?php
if (isset($myDate)) {
$myDate=$joblist-&gt;DBDate($myDate);
}
?&gt;&lt;?php
// *** Edit Operations: declare Tables
$MM_editAction = $PHP_SELF;
if ($QUERY_STRING) {
$MM_editAction = $MM_editAction . "?" . $QUERY_STRING;
}

$MM_abortEdit = 0;
$MM_editQuery = "";
?&gt;
&lt;?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 &lt; 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) &gt; 0)) {
$MM_editRedirectUrl .= ((strpos($MM_editRedirectUrl, '?') == false)?"?":"&" . $QUERY_STRING;
}
}
?&gt;
&lt;?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 &lt; 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-&gt;Execute($MM_editQuery) or DIE($joblist-&gt;ErrorMsg());
if ($MM_editRedirectUrl) {
header ("Location: $MM_editRedirectUrl";
}
}
}
?&gt;&lt;?php


?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Job Insert&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;/head&gt;
&lt;body bgcolor="#FFFFFF" text="#000000"&gt;
&lt;table cellspacing=1 cellpadding=5 width="100%" border=0 bgcolor="#000000"&gt;
&lt;tr bgcolor=#98CCC8&gt;
&lt;td align="left"&gt;&lt;font face="Arial, Helvetica, sans-serif"
size=3 color="#003366"&gt;&lt;b&gt;&lt;i&gt;CREATE NEW JOB&lt;/i&gt;&lt;/b&gt;&lt;/font&gt; &lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;form ACTION="&lt;?php echo $MM_editAction?&gt;" METHOD="POST" name="InsertForm"&gt;
&lt;table align="center" width="100%" cellspacing="1" bordercolor="#000000" border="0" cellpadding="1" bgcolor="#000000"&gt;
&lt;tr valign="baseline"&gt;
&lt;td nowrap align="right" bgcolor="#FFFFFF"&gt;Job Ref:&lt;/td&gt;
&lt;td bgcolor="#FFFFFF"&gt;
&lt;input type="text" name="job_ref" size="32" &gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="baseline"&gt;
&lt;td nowrap align="right" bgcolor="#FFFFFF"&gt;Title:&lt;/td&gt;
&lt;td bgcolor="#FFFFFF"&gt;
&lt;input type="text" name="job_title" size="32"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="baseline"&gt;
&lt;td nowrap align="right" bgcolor="#FFFFFF"&gt;Industry:&lt;/td&gt;
&lt;td bgcolor="#FFFFFF"&gt;
&lt;select name="select" size="1"&gt;
&lt;option value="NO INDUSTRY"&gt;Please Select&lt;/option&gt;
&lt;/select&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="baseline" bgcolor="#FFFFFF"&gt;
&lt;td nowrap align="right" bgcolor="#FFFFFF"&gt;Business Area:&lt;/td&gt;
&lt;td&gt;
&lt;input type="text" name="job_bus_area" size="32"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="baseline"&gt;
&lt;td nowrap align="right" bgcolor="#FFFFFF"&gt;Duration:&lt;/td&gt;
&lt;td bgcolor="#FFFFFF"&gt;
&lt;input type="text" name="job_duration" size="32"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="baseline"&gt;
&lt;td nowrap align="right" bgcolor="#FFFFFF"&gt; Salary:&lt;/td&gt;
&lt;td bgcolor="#FFFFFF"&gt;
&lt;input type="text" name="job_salary" size="32"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="baseline"&gt;
&lt;td nowrap align="right" bgcolor="#FFFFFF"&gt;Location:&lt;/td&gt;
&lt;td bgcolor="#FFFFFF"&gt;
&lt;input type="text" name="job_location" size="32"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="baseline"&gt;
&lt;td nowrap align="right" bgcolor="#FFFFFF"&gt; Contact Email:&lt;/td&gt;
&lt;td bgcolor="#FFFFFF"&gt;
&lt;select name="email" size="1"&gt;
&lt;option value="NO EMAIL ADDRESS"&gt;Please Select&lt;/option&gt;
&lt;/select&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="baseline"&gt;
&lt;td nowrap align="right" valign="top" bgcolor="#FFFFFF"&gt;Description:&lt;/td&gt;
&lt;td bgcolor="#FFFFFF"&gt;
&lt;textarea name="job_description" cols="60" rows="5"&gt;&lt;/textarea&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="baseline"&gt;
&lt;td nowrap align="right" bgcolor="#FFFFFF"&gt;Hot Job (check):&lt;/td&gt;
&lt;td bgcolor="#FFFFFF"&gt;
&lt;input type="checkbox" name="Job_hot" value="checkbox"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;tr valign="baseline"&gt;
&lt;td nowrap align="right" bgcolor="#98CCC8"&gt;&nbsp; &lt;/td&gt;
&lt;td bgcolor="#98CCC8"&gt;
&lt;input type="submit" name="Insert Record" value="Insert Record"&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;/table&gt;
&lt;input type="hidden" name="job_id"&gt;
&lt;input type="hidden" name="myDate" value="&lt;?php echo date("m/d/Y"; ?&gt;"&gt;
&lt;input type="hidden" name="MM_insert" value="true"&gt;

&lt;/form&gt;
&lt;p&gt;&nbsp;&lt;/p&gt;
&lt;/body&gt;
&lt;/html&gt;


here is the code -

Reply to this topic