This php error killing me

Hai folks,

do you see any syntax error in this piece of code?

<?php

include("../includes/connection.php");
include("../includes/set_time_zone.php");

$log_username=$_SESSION['username']; //correctly pirints the username currently loged in when echo
$log_dt=date("Y/m/d h:i:s A"); //correctly prints the time and date when echo

function reglog($event){
	$query = "INSERT into logs VALUES ('','$event','$log_username','$log_dt')";
	if ($result=mysql_query($query) or die (mysql_error()));
}
?>

it says

Undefined variable: log_username…
Undefined variable: log_dt

Your error is in the function. $log_username and $log_dt are NOT part of the function scope. You passed in $event but you forgot to pass in $log_username and $log_dt.

http://www.php.net/manual/en/language.variables.scope.php

Done!!! Thanks a bunch logic_earth!!!


function reglog($event){
    $log_username=$_SESSION['username'];
    $log_dt=date("Y/m/d h:i:s A");
	$query = "INSERT into logs VALUES ('','$event','$log_username','$log_dt')"; 
	if ($result=mysql_query($query) or die (mysql_error()));
}

You need to include session_start() and if $_SESSION[‘username’] is not set you have to set it.

Example:

<?php
   session_start();
   include("../includes/connection.php");
   include("../includes/set_time_zone.php");

   if (!isset($_SESSION['username']))
   {
	   $_SESSION['username'] = "log_username";
   }
   $log_username=$_SESSION['username']; //correctly pirints the username currently loged in when echo
   $log_dt=date("Y/m/d h:i:s A"); //correctly prints the time and date when echo

   function reglog($event){
	   $query = "INSERT into logs VALUES ('','$event','$log_username','$log_dt')"; 
	   if ($result=mysql_query($query) or die (mysql_error()));
   }
?>

I’m not sure why you getting error for $log_dt.

EDIT: If reglog() was called it would generate those errors as logic_earth stated.

Thanks tom for the additional help!