sql - Create insert function in php -


hello have logs table in database , in every user action log in, log out, edit, delete, create, want logged. here current code in every action:

    $action = "log in"; //if user log in     $query = "insert tbllogs              (logorigin,               logaction,               loguser,               logdate,               logoutcome)                values             (:origin,               :action,               :user,               :dt,               :outcome)";                $stmt = $dbc->prepare($query);               $stmt->bindparam(':origin', $ip);               $stmt->bindparam(':action', $action);               $stmt->bindparam(':user', $_session['id']);               $stmt->bindparam(':dt', $datetime);               $stmt->bindparam(':outcome', $outcome);               $stmt->execute(); 

what wanted instead of repeating code in every user action, want create function this. problem is, using different values in $action variable example if user log in, $action = "log in", if user logs out, $action = "log out". how can accomplish that? thank you!

make following function in file , include on every page want log activity. , call function variable follows:

logging('log in',$ip,$outcome);

function logging($action=null,$ip,$outcome){     $query = "insert tbllogs (logorigin, logaction, loguser, logdate, logoutcome) values (:origin, :action, :user, :dt, :outcome)";               $stmt = $dbc->prepare($query);               $stmt->bindparam(':origin', $ip);               $stmt->bindparam(':action', $action);               $stmt->bindparam(':user', $_session['id']);               $stmt->bindparam(':dt', $datetime);               $stmt->bindparam(':outcome', $outcome);               $stmt->execute(); } 

hope helps.


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -