This topic is locked

use current date NOW ()

7/5/2007 12:51:01 PM
PHPRunner General questions
M
mounir author

hello ,

i use PhPrunner 4.0 and i have a Date field in a table the fiel name is "last_update_date" so wend editing that table ,i want to insert the current date in that field

in the default value of the field i have : now()

the problem is :

in the phprunner code "*_edit.php" i have :
foreach($evalues as $ekey=>$value)

{

$strSQL.=AddFieldWrappers($ekey)."=".add_db_quotes($ekey,$value).", ";

}
and with that, the $strSQL i get contains :

`last_update_date`='date(NOW())'
can you help me with that , thank you

L
larsonsc 7/5/2007

I use a BeforeEdit event to do this in one of my projects. In the events screen, click the table you want, then table events, Edit page, Before record updated and then try this code:

//********** Insert a record into another table ************

global $conn;

$strSQLInsert = "update _TABLENAME

set last_update_date = now()

where IDFIELD = '".$values["IDFIELD"]."'";

db_exec($strSQLInsert,$conn);
return true;


You will need to modify _TABLENAME to your actual table, and IDFIELD to whatever your primary key field is named. Hope that works for you.

B
Blooper 9/21/2007

I use a BeforeEdit event to do this in one of my projects. In the events screen, click the table you want, then table events, Edit page, Before record updated and then try this code:


//********** Insert a record into another table ************

global $conn;

$strSQLInsert = "update _TABLENAME

set last_update_date = now()

where IDFIELD = '".$values["IDFIELD"]."'";

db_exec($strSQLInsert,$conn);
return true;


You will need to modify _TABLENAME to your actual table, and IDFIELD to whatever your primary key field is named. Hope that works for you.


Good day.
I've tried this code with all my database's settings., but I get an error can can not find/does not know what the $values are.? Does this also need to be defined?
Thanks

Admin 9/21/2007

Hi,
this code works in Before record added/updated events.

$values array contain user-entered values there.

B
Blooper 9/21/2007

Hi,

this code works in Before record added/updated events.

$values array contain user-entered values there.


Hello thanks so much. I will go and try is now.
Thanks again for replying

B
Blooper 9/21/2007



Hello thanks so much. I will go and try is now.
Thanks again for replying


Hello again. I think I'm doing something wrong. Here is the error I get agter uploading it.
Error type 8

Error description Undefined variable: values

URL www.nvg.co.za/php/register.php?

Error file /var/www/vhosts/nvg.co.za/httpdocs/php/include/events.php

Error line 41

SQL query select count(*) from `Models` where `contact_email`='lop@lop.com'
Still complains about the "$values.
I need to change the date_join to the currant date to show when the person signed up.
Here is the code I have. ____-
function BeforeRegister($userdata)

{

// Parameters:

// $userdata - Array.

// Each field on this form represented as 'Field name'-'Field value' pair
//** Insert a record into another table ****

global $conn;

$strSQLInsert = "update Models

set date_join = now()

where id = '".$values["id"]."'";

dbexec($strSQLInsert,$conn);
return true;
// return true if you like to proceed with registration

// return false in other case
} // function BeforeRegister

____

B
Blooper 9/21/2007



Hello again. I think I'm doing something wrong. Here is the error I get agter uploading it.
Error type 8

Error description Undefined variable: values

URL www.nvg.co.za/php/register.php?

Error file /var/www/vhosts/nvg.co.za/httpdocs/php/include/events.php

Error line 41

SQL query select count(*) from `Models` where `contact_email`='lop@lop.com'
Still complains about the "$values.
I need to change the date_join to the currant date to show when the person signed up.
Here is the code I have. ____-
function BeforeRegister($userdata)

{

// Parameters:

// $userdata - Array.

// Each field on this form represented as 'Field name'-'Field value' pair
//** Insert a record into another table ****

global $conn;

$strSQLInsert = "update Models

set date_join = now()

where id = '".$values["id"]."'";

dbexec($strSQLInsert,$conn);
return true;
// return true if you like to proceed with registration

// return false in other case
} // function BeforeRegister

____



Just a though. I'm Using mysql. It can be because this is for another type of database?
Thanks.

Admin 9/21/2007

In the Before Registerevent use $userdatainstead of$values.