Problem in PHP Calendar Event

Good day!

I created a webpages and i have a login page consist of Username and Department. And i encountered problem in adding event in my calendar.

This is the flow of my webpage:
First I have a separate table for the user and calendar. In my user table it has a Username, Department, and Permission. In the permission I put True or False, only one user i put True because i want that user is the one who permitted to add event or if she is login the add event link appear, but if other login the add even0t did not appear.

This is my code in login:
[php]

<?php session_start(); session_regenerate_id(); if($_SESSION['loggedin']){ //the user is already logged in, lets redirect them to the other page header("Location:company.php"); } //require_once 'conn.php'; $db_name="dspi"; mysql_connect("localhost", "root", "") or die("Cannot connect to server"); mysql_select_db("$db_name")or die("Cannot select DB"); $department = mysql_real_escape_string($_POST['department']); $username = mysql_real_escape_string($_POST['username']); $sql=mysql_query("SELECT `Department`, `Username` FROM `tbllogin` WHERE `Department` = '{$department}' AND Username = '{$username}'") or die(mysql_error()); $ct = mysql_num_rows($sql); if($ct == 1) { // im guessing this means that the user is valid. $_SESSION['loggedin'] = true; // now that the user is valid we change the session value. $row = mysql_fetch_assoc($sql); $_SESSION['username'] = $row['Username'] ; $_SESSION['department'] = $row['Department']; $Departments=array('Accounting', 'Engineering', 'Finishing_Goods', 'HRAD', 'MIS', 'Packaging_and_Design', 'Production', 'Purchasing_Logistic', 'QA_and_Technical', 'Supply_Chain'); if (in_array($row['Department'], $Departments)){ header ('Location:company.php'); }else{ echo "Incorrect Username or Department"; header ('Location:index.php'); } } ?>

[/php]

and this is my code in calendar page:

[php]

<?php session_start(); $host = "localhost"; $username = ""; $password = ""; $dbCnx = @mysql_connect($host, $username, $password) or die('Could not Connect to the database'); $dbName = 'dspi'; mysql_select_db($dbName); ?> <?php //$todaysDate = date("n/j/Y"); //echo $todaysDate; // Get values from query string $day = (isset($_GET["day"])) ? $_GET['day'] : ""; $month = (isset($_GET["month"])) ? $_GET['month'] : ""; $year = (isset($_GET["year"])) ? $_GET['year'] : ""; //comparaters for today's date //$todaysDate = date("n/j/Y"); //$sel = (isset($_GET["sel"])) ? $_GET['sel'] : ""; //$what = (isset($_GET["what"])) ? $_GET['what'] : ""; //$day = (!isset($day)) ? $day = date("j") : $day = ""; if(empty($day)){ $day = date("j"); } if(empty($month)){ $month = date("n"); } if(empty($year)){ $year = date("Y"); } //set up vars for calendar etc $currentTimeStamp = strtotime("$year-$month-$day"); $monthName = date("F", $currentTimeStamp); $numDays = date("t", $currentTimeStamp); $counter = 0; //$numEventsThisMonth = 0; //$hasEvent = false; //$todaysEvents = ""; //run a selec statement to hi-light the days function hiLightEvt($eMonth,$eDay,$eYear){ //$tDayName = date("l"); $todaysDate = date("n/j/Y"); $dateToCompare = $eMonth . '/' . $eDay . '/' . $eYear; if($todaysDate == $dateToCompare){ //$aClass = '' . $tDayName . ''; $aClass='class="today"'; }else{ //$dateToCompare = $eMonth . '/' . $eDay . '/' . $eYear; //echo $todaysDate; //return; $sql="select count(calDate) as eCount from calTbl where calDate = '" . $eMonth . '/' . $eDay . '/' . $eYear . "'"; //echo $sql; //return; $result = mysql_query($sql); while($row= mysql_fetch_array($result)){ if($row['eCount'] >=1){ $aClass = 'class="event"'; }elseif($row['eCount'] ==0){ $aClass ='class="normal"'; } } } return $aClass; } ?>
<?php for($i = 1; $i < $numDays+1; $i++, $counter++){ $dateToCompare = $month . '/' . $i . '/' . $year; $timeStamp = strtotime("$year-$month-$i"); //echo $timeStamp . '
'; if($i == 1){ // Workout when the first day of the month is $firstDay = date("N", $timeStamp); for($j = 1; $j < $firstDay; $j++, $counter++){ echo ""; } } if($counter % 7 == 0 ){ ?> <?php } ?> <?php } ?>
);"> <?php echo $monthName . " " . $year; ?>
);">
M T W T F S S
 
><?=$i;?>
<?php if(isset($_GET['v'])){ if(isset($_POST['Submit'])){ $sql="insert into calTbl(calName,calDesc,calDate,calStamp) values('" . $_POST['calName'] ."','" . $_POST['calDesc'] . "','" . $_POST['calDate'] . "',now())"; mysql_query($sql); } $sql="select calName,calDesc, DATE_FORMAT(calStamp, '%a %b %e %Y') as calStamp from calTbl where calDate = '" . $month . '/' . $day . '/' . $year . "'"; //echo $sql; //return; $result = mysql_query($sql); $numRows = mysql_num_rows($result);

$check=mysql_query(“SELECT * FROM tbllogin WHERE Username=‘xxx’ AND Department=‘HRAD’ AND Permission=‘True’”);
mysql_fetch_array($check);
if($check[‘Username’]==‘xxx’ && $check[‘Department’]==‘HRAD’){
$_SESSION[‘isallowed’] = $check[‘Permission’];

//if (mysql_num_rows($check)>0){
?>
Add Event<?php
}else{
echo ‘You cannot Add New Event’;
}?>

<?php if(isset($_GET['f'])){ include 'calform.php'; } if($numRows == 0 ){ echo ''; }else{ //echo '
    '; echo '

    Event Listed

    '; while($row = mysql_fetch_array($result)){ ?>
    <?=$row['calName'];?>
    <?=$row['calDesc'];?>
    Listed On: <?=$row['calStamp'];?> <?php } } } ?>
[/php]

In that code when the user log is xxx and when she click a date she want to add event the appear is “You cannot Add Event”.

I hope somebody can help me…

Thank you in advance…

Sponsor our Newsletter | Privacy Policy | Terms of Service