-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathaddItem.php
More file actions
89 lines (83 loc) · 3.06 KB
/
addItem.php
File metadata and controls
89 lines (83 loc) · 3.06 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
session_start();
include('db.php');
include('header.php');
if(!isset($_SESSION['key']))
{
header("Location: /stuff-sharing/login.php?error=NOT_LOGIN");
}
else
{
$email = pg_escape_string($connection,$_SESSION['key']);
$query = "SELECT firstName, lastName, userpoint FROM users where email='".$email."'";
$result = pg_query($connection,$query) or die('Query failed:'.pg_last_error());
$row = pg_fetch_row($result);
}
if(isset($_POST['action']) && $_POST['action'] == "addItem")
{
$itemName = pg_escape_string($connection,$_POST['itemName']);
$itemDescription = pg_escape_string($connection,$_POST['itemDescription']);
$itemCategory = pg_escape_string($connection,$_POST['itemCategory']);
$addItemQuery = "insert into ItemList(itemName,itemDescription,itemCategory,ownerEmail) values ('"
. $itemName ."','" . $itemDescription ."', '" .$itemCategory."', '".$email."')";
$addItemResult = pg_query($connection, $addItemQuery);
if($addItemResult){
echo ("
<div class=\"alert alert-info\">
<a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">×</a>
Item added!
</div>
");
}
}
?>
<body>
<?php
include('navbar.php');
?>
<div class="container">
<div class="row">
<div class="col-md-4 col-md-offset-4">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Add Item Page</h3>
</div>
<div class="panel-body">
<?php
if(isset($message))
{
echo '<div class="alert alert-danger" role="alert">
<span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span>
<span class="sr-only">Error:</span>' .
$message .
'</div>';
}
?>
<form action="addItem.php" method="post">
<fieldset>
<div class="form-group">
<input class="form-control" id="item-name" name="itemName" type="text" placeholder="Item Name" autofocus>
</div>
<div class="form-group">
<input class="form-control" id="item-description" name="itemDescription" type="text" placeholder="Item Description">
</div>
<div class="form-group">
<select class="form-control" id="categories" name="itemCategory">
<option value = 'Home'>Home Use</option>
<option value = 'Phone'>Phone</option>
<option value = 'School'>School Use</option>
<option value = 'Personal'>Personal Use</option>
<option value = 'Other'>Other</option>
</div>
<div class="form-group">
<input class="form-control" name="action" type="hidden" value="addItem" />
</div>
<button type="submit" class="btn btn-success btn-block">addItem</button>
</fieldset>
</form>
</div>
</div>
</div>
</div>
</div>
</body>