- strftime: documentation ( source)
- date_default_timezone_set: documentation ( source)
- session_start: documentation ( source)
- header: documentation ( source)
<?php
include "connect.php";
session_start();
date_default_timezone_set('UTC');
if($_SESSION['user']){
}
else{
header("location:index.php");
}
if($_SERVER['REQUEST_METHOD'] = "POST") //Added an if to keep the page secured
{
$details = $con->real_escape_string($_POST['details']);
$time = strftime("%X");//time
$date = strftime("%B %d, %Y");//date
$decision ="no";
$con->select_db("main") or die("Cannot connect to database"); //Connect to database
foreach($_POST['public'] as $each_check) //gets the data from the checkbox
{
if($each_check !=null ){ //checks if the checkbox is checked
$decision = "yes"; //sets teh value
}
}
$con->query("INSERT INTO list (details, date_posted, time_posted, public) VALUES ('$details','$date','$time','$decision')"); //SQL query
header("location: home.php");
}
else
{
header("location:home.php"); //redirects back to hom
}
?>