This topic is locked

Updating time and username from edit

11/3/2006 5:10:29 PM
PHPRunner General questions
G
gdude66 author

Hi

I have a table that I want to update the username of the person editing the table and used the $_session(userid) in the default edit field and made the filed hidden. On edit the userid is not passing to the table and the same with the timestamp which I again use a hidden field and the now() as default.
Any reason why this doesn't work from the edit section but works from the add new?

T
thesofa 11/3/2006

default values only seem to work on the add page, if you want to add values on edit, you need to do it through events

J
Jane 11/7/2006

Graeme,
to add default values on the EDIT page use Before record updated event on the Events tab.

Here is a sample code:

function BeforeEdit(&$values, $where)

{

$values["Updatedby"] = $_SESSION["UserID"];

$values["UpdatedDate"] = now();

return true;

}



where Updatedby and UpdatedDate are your actual field names.

G
gdude66 author 11/7/2006

Graeme,

to add default values on the EDIT page use Before record updated event on the Events tab.

Here is a sample code:
where Updatedby and UpdatedDate are your actual field names.



Thanks Jane

This works but returns username and doesn't convert it to idstaff. Is there a way to do that?

J
Jane 11/7/2006

to get idstaff use following code:

global $conn;

$str = "select idstaff from TableName where UserName='".$_SESSION["UserID"]."'";

$rs = db_query($str,$conn);

$data = db_fetch_array($rs);

$values["Updatedby"] = $data["idstaff"];



where UserName is your actual field name, Tablename is your actual table name.

G
gdude66 author 11/7/2006

to get idstaff use following code:

where UserName is your actual field name, Tablename is your actual table name.



Fantastic Jane - That solved all of my problems. Well done.

While I am here - great program - great support.