This topic is locked

Looging Code Needed

7/29/2006 11:01:20 PM
PHPRunner General questions
D
dmyers author

I need to figure out how to add logging to the PHPRunner code. I have already highly customized the code for other features and really prefer not to have to "Build" it again. It took along time to get it the way I wanted it.
What I need is some code that can be inserted into the generated pages that will log all deleted records with the date, time, IP Address and userid of the person who deleted the record.
This is for an arrest warrant database and we have to be able to see what people are doing in the database. We have already got it where users can only edit or delete records entered by their police department, but we have nothing in the event someone gets pissed off and starts deleting warrants out of the system.
The code can add them to another table, or put them in a text file on the server. Either one works for us.
If anyone can help with this I would be very helpful.
Here is a link to the site ...
Username: Demo

Password: Demo
Thanks,
David Myers

kujox 7/30/2006

David,
Do you need to keep the record intact and just 'hide' the record as deleted, so you can place the record id in the logging table, I would do this as I could then see what the user had deleted.
All you need to do then is add a field using phpmyadmin which is called deleted or active , you could even add the user, ip and timestamp to this table as well.
PS, a bloke on there called jason agee, he looks a lot like harold shipman

J
Jane 7/31/2006

David,
sure you can do it using events. Here is a sample code:

function BeforeDelete($where)

{

global $conn;

$str = "select * from products where ".$where;

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

$data = db_fetch_array($rs);

$strinsert = "insert into LogTable (UserID, DeletedDate, IDAddress, LastName, FirstName) values ('".$_SESSION["UserID"].'",now(),'".$_SERVER["REMOTE_ADDR"]."',".$data["LastName"].",".$data["FirstName"].")";

db_exec($strinsert,$conn);

return true;

}



Put this code to the include/warrant_info_events.php file.

D
dmyers author 7/31/2006

David,

Do you need to keep the record intact and just 'hide' the record as deleted, so you can place the record id in the logging table, I would do this as I could then see what the user had deleted.
All you need to do then is add a field using phpmyadmin which is called deleted or active , you could even add the user, ip and timestamp to this table as well.
PS, a bloke on there called jason agee, he looks a lot like harold shipman


All of the data on there is fake for now. When it goes live we have to enter about 30,000 warrants.
Thanks...

David,

sure you can do it using events. Here is a sample code:
Put this code to the include/warrant_info_events.php file.


How would I get this to log (in order) the warrant number, agency ori, last name, first name, ip address, who deleted, date, time.
Thanks for the help...

J
Jane 8/1/2006

David,
here is a correct code:

function BeforeDelete($where)

{

global $conn;

$str = "select * from warrant_info where ".$where;

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

$data = db_fetch_array($rs);

$strinsert = "insert into LogTable (UserID, DeletedDate, IDAddress, WarrantNumber, AgencyOri, LastName, FirstName) values ('".$_SESSION["UserID"].'",now(),'".$_SERVER["REMOTE_ADDR"]."',".$data["WarrantNumber"].",".$data["AgencyOri"].",".$data["LastName"].",".$data["FirstName"].")";

db_exec($strinsert,$conn);

return true;

}



where UserID is a person who deleted record, IPAddress is his ip address, DeletedDate is a date and time when this record was deleted, WarrantNumber, AgencyOri, LastName and FirstName - info about warrant.

D
dmyers author 8/25/2006

I get this message when I try it. I have looked all over the code and cant find what is wrong. Probably something real small.
Parse error: syntax error, unexpected '"' in /home/robinson/public_html/portal/restricted/warrant_search/include/warrant_info_events.php on line 9


Line # 9 starts with $strinsert
Here is the code.

<?php
function BeforeDelete($where)

{

global $conn;

$str = "select * from warrant_info where ".$where;

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

$data = db_fetch_array($rs);

$strinsert = "insert into log_table (UserID, DeletedDate, IDAddress, WarrantNumber, AgencyOri, LastName, FirstName) values ('".$_SESSION["UserID"].'",now(),'".$_SERVER["REMOTE_ADDR"]."',".$data["WarrantNumber"].",".$data["AgencyOri"].",".$data["LastName"].",".$data["FirstName"].")";

db_exec($strinsert,$conn);

return true;

}
?>


Thanks for helping me guys...

J
Jane 8/25/2006

David,
please note that if your field type is VARCHAR or TEXT you should use single quotes, e.g.

$str = "insert into log_table (LastName) values ('".$data["LastName"]."')"

<?php

function BeforeDelete($where)

{

global $conn;

$str = "select * from warrant_info where ".$where;

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

$data = db_fetch_array($rs);

$strinsert = "insert into log_table (UserID, DeletedDate, IDAddress, WarrantNumber, AgencyOri, LastName, FirstName) values ('".$_SESSION["UserID"].'",now(),'".$_SERVER["REMOTE_ADDR"]."',".$data["WarrantNumber"].",".$data["AgencyOri"].",'".$data["LastName"]."','".$data["FirstName"]."')";

db_exec($strinsert,$conn);

return true;

}
?>