forked from kristianguevara/MyFirstWebsite
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.php
32 lines (29 loc) · 944 Bytes
/
add.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
session_start();
if($_SESSION['user']){
}
else{
header("location:index.php");
}
if($_SERVER['REQUEST_METHOD'] = "POST") //Added an if to keep the page secured
{
$details = mysql_real_escape_string($_POST['details']);
$time = strftime("%X");//time
$date = strftime("%B %d, %Y");//date
$decision ="no";
mysql_connect("localhost", "root","") or die(mysql_error()); //Connect to server
mysql_select_db("first_db") 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
}
}
mysql_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
}
?>