-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathorders_crud.php
More file actions
57 lines (57 loc) · 2 KB
/
orders_crud.php
File metadata and controls
57 lines (57 loc) · 2 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
<?php
include_once 'database.php';
$conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if (isset($_POST['create'])) {
try {
$stmt = $conn->prepare("INSERT INTO tbl_orders_a176607_pt2(fld_order_id, fld_staff_id, fld_customer_id) VALUES(:oid, :sid, :cid)");
$stmt->bindParam(':oid', $oid, PDO::PARAM_STR);
$stmt->bindParam(':sid', $sid, PDO::PARAM_STR);
$stmt->bindParam(':cid', $cid, PDO::PARAM_STR);
$oid = uniqid('O', true);
$sid = $_POST['sid'];
$cid = $_POST['cid'];
$stmt->execute();
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
if (isset($_POST['update'])) {
try {
$stmt = $conn->prepare("UPDATE tbl_orders_a176607_pt2 SET fld_staff_id = :sid, fld_customer_id = :cid WHERE fld_order_id = :oid");
$stmt->bindParam(':oid', $oid, PDO::PARAM_STR);
$stmt->bindParam(':sid', $sid, PDO::PARAM_STR);
$stmt->bindParam(':cid', $cid, PDO::PARAM_STR);
$oid = $_POST['oid'];
$sid = $_POST['sid'];
$cid = $_POST['cid'];
$stmt->execute();
header("Location: orders.php");
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
if (isset($_GET['delete'])) {
try {
$stmt = $conn->prepare("DELETE FROM tbl_orders_a176607_pt2 WHERE fld_order_id = :oid");
$stmt->bindParam(':oid', $oid, PDO::PARAM_STR);
$oid = $_GET['delete'];
$stmt->execute();
header("Location: orders.php");
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
if (isset($_GET['edit'])) {
try {
$stmt = $conn->prepare("SELECT * FROM tbl_orders_a176607_pt2 WHERE fld_order_id = :oid");
$stmt->bindParam(':oid', $oid, PDO::PARAM_STR);
$oid = $_GET['edit'];
$stmt->execute();
$editrow = $stmt->fetch(PDO::FETCH_ASSOC);
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
$conn = null;
?>