-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate.php
More file actions
58 lines (51 loc) · 2.16 KB
/
create.php
File metadata and controls
58 lines (51 loc) · 2.16 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php session_start(); /* Starts the session */
if(!isset($_SESSION['UserData']['Username'])){
header("location:login.php");
exit;
}
?>
<?php
include 'functions.php';
$pdo = pdo_connect_mysql();
$msg = '';
// Check if POST data is not empty
if (!empty($_POST)) {
// Post data not empty insert a new record
// Set-up the variables that are going to be inserted, we must check if the POST variables exist if not we can default them to blank
$id = isset($_POST['id']) && !empty($_POST['id']) && $_POST['id'] != 'auto' ? $_POST['id'] : NULL;
// Check if POST variable "name" exists, if not default the value to blank, basically the same for all variables
$name = isset($_POST['name']) ? $_POST['name'] : '';
$info = isset($_POST['info']) ? $_POST['info'] : '';
$deadline = isset($_POST['deadline']) ? $_POST['deadline'] : '';
$status = isset($_POST['status']) ? $_POST['status'] : '';
$owner = isset($_POST['owner']) ? $_POST['owner'] : '';
// Insert new record into the contacts table
$stmt = $pdo->prepare('INSERT INTO worklist VALUES (?, ?, ?, ?, ?, ?)');
$stmt->execute([$id, $name, $info, $deadline, $status, $owner]);
// Output message
$msg = 'Created Successfully!';
}
?>
<?=template_header('Create New Task - Vito Karyadi')?>
<div class="content update">
<h2>Create New Task</h2>
<form action="create.php" method="post">
<label for="id">ID</label>
<input type="text" name="id" value="auto" id="id">
<label for="name">Task Name</label>
<input type="text" name="name" id="name">
<label for="info">Information</label>
<input type="text" name="info" id="info">
<label for="deadline">Deadline</label>
<input type="text" name="deadline" id="deadline">
<label for="status">Status</label>
<input type="text" name="status" value="0" id="status">
<label for="owner">Created by</label>
<input type="text" name="owner" id="owner">
<input type="submit" value="Create">
</form>
<?php if ($msg): ?>
<p><?=$msg?></p>
<?php endif; ?>
</div>
<?=template_footer()?>