Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Advice about date insertion (Old thread)

Status
Not open for further replies.

keepingbusy

Programmer
Apr 9, 2000
1,470
GB

Hi

I am looking for a solution to insert the current date when someone updates a record online as part of a content management system.

Previous thread: thread434-1219483

That thread shows coding:
Code:
$sql = "insert into [b]DBTABLE[/b] set createtime=now()";
Is the DBTABLE a field name or is it the actual database?

Also, where would I insert the coding above to ensure the field in our table field name updatedon will be replaced with the date the record was updated?

Thank you
 
createtime is the date field name.
You would put the createtime=now()"; in the query that updates your fields.


Such as:

Code:
UPDATE mytablenane  set fieldname1=whatever fieldname2=somethingelse.... datefieldname=now(); ...
WHERE ...

etc...

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 

Hi vacunita

I am sorry, but you have lost me on this one. My knowledge is fairly good but perhaps you could explain it in a simplified manner.

Lets say my database is called PROPTABLE and the date field is UPDATEON

So you are saying:
UPDATE mytablenane set fieldname1=whatever fieldname2=somethingelse.... datefieldname=now(); ...
WHERE ...
so if I change the above to:
Code:
[b]UPDATE PROPTABLE[/b]

I am lost with the rest and how it would be incorporated with the rest of my code.

Is it possible to insert a single line of code so when the record is updated by a user clicking on the save button, it then inserts todays date?

Thank you
 
How is your record updated?

There should be a place where you have the update statement already made, in the update statement you add the last section to update the field that is of type date or time stamp so it can hold a date.


So yes, if your table name is proptable then your update statement looks like:

Code:
[blue]UPDATE [b][red]PROPTABLE[/red][/b] SET ... [b][red]UPDATEON=now();[/red][/b] WHERE ... [/blue]









----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
proptable is more likely to be the name of your table, and not your database.

just an aside.
 
The name of your database does not come into play in the update statement. That should have already been determined in your connection prior to issuing the update statement.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 

Hi

Regarding the above code suggestions, I have looked through the particular php file (called edit.php) and cannot find anything that resembles
Code:
UPDATE PROPTABLE SET ... UPDATEON=now(); WHERE ...
Below, is an edited version of the file I am trying to use to replace the DATE field with the current date. It looks something like this:
Code:
echo "<h4>Edit Listing</h4>";
echo "<form action='edit2.php' method=post>";
echo "<table cellpadding=2 cellspacing=0 width='100%'>";
echo "<tr >";
echo "<td colspan=2 class='subHeader'>*Fields will validate on submit</td>";
echo "</tr>";

while( $field = mysql_fetch_assoc($result) ){
if($field['Type'] != "Mapping"){
switch($field['Type']){
case "text":
echo "<tr>";
echo "<td valign='top' width='30%'><strong>".$field['Title']."</strong></td>";
echo "<td >";			
		
if( ($field['MaxChars']*1) > 0 )

[b]More code.... etc[/b]

break;

case "textarea":
echo "<tr>";
echo "<td valign='top'><strong>".$field['Title']."</strong></td><td>";
				
if( ($field['MaxChars']*1) > 0 ){
$max = $field['MaxChars'];
$id = $field['Title'].'_message';

[b]More code.... etc[/b]

break;

case "select":
echo "<tr>";
echo "<td valign='top' width='30%'><strong>".$field['Title']."</strong></td>";
echo "<td >";						
echo "<select name='".$field['Title']."'>";
$node = new sqlNode();

[b]More code.... etc[/b]

break;
When we get to this point at the end of the record update, there is this code:
Code:
echo "<tr>";
echo "<td>&nbsp;</td><td>";
echo "<input type='hidden' name='TypeID' value='".$_GET['TypeID']."'>";
echo "<input type='hidden' name='ID' value='".$_GET['ListingID']."'>";	
echo "<input type='submit' value='Save' onClick='validate(this.form); return document.formSubmit;'>";
echo "</td>";
echo "</tr>";
echo "</table>";
So where do I insert the relevant code so I can replace my DATE field with the current date and what code do I need to insert/use so the record will be updated after I click on the Save button?

Thank you
 
That code you posted does not have any place where an update would be taking place. Judging by the form code at the beginning, I would assume the update is taking place in edit2.php.

Look at that one and look for the Update statement.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top