-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathproductprocess.php
More file actions
69 lines (50 loc) · 1.86 KB
/
productprocess.php
File metadata and controls
69 lines (50 loc) · 1.86 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
<?php
session_start();
$mysqli = new mysqli('localhost','root','','explore_setyle') or die(mysqli_error($mysqli));
$id = 0;
$update = false;
$product_name = '';
$category='';
$sub_category='';
$price='';
if (isset($_POST['add'])){
$product_name = $_POST['product_name'];
$category = $_POST['category'];
//$user_name = $_POST['user_name'];
$sub_category = $_POST['sub_category'];
$price = $_POST['price'];
$mysqli->query("INSERT INTO products (product_name,category,sub_category,price) VALUES('$product_name', '$category', '$sub_category', '$price')") or die($mysqli->error);
$_SESSION['massage'] = "Record has been saved(=";
$_SESSION['mas_type'] = "success";
header("location:addproducts.php");
}
if (isset($_GET['delete'])) {
$id = $_GET['delete'];
$mysqli->query("DELETE FROM products WHERE id=$id") or die ($mysqli->error());
$_SESSION['massage'] = "Record has been deleted!!!!!!!";
$_SESSION['mas_type'] = "denger";
header("location:addproducts.php");
}
if (isset($_GET['edit'])) {
$id = $_GET['edit'];
$update = true;
$result = $mysqli->query("SELECT * FROM products WHERE id=$id") or die ($mysqli->error());
if (count($result)==1){
$row = $result->fetch_array();
$product_name = $row['product_name'];
$category = $row['category'];
$sub_category = $row['sub_category'];
$price = $row['price'];
}
}
if (isset($_POST['update'])){
$id =$_POST['id'];
$product_name = $_POST['product_name'];
$category = $_POST['category'];
$sub_category = $_POST['sub_category'];
$price = $_POST['price'];
$mysqli->query("UPDATE products SET product_name='$product_name', category='$category', sub_category='$sub_category', price='$price' WHERE id=$id") or die ($mysqli->error);
$_SESSION['massage'] = "Details has been update";
$_SESSION['msg_type'] ="warning";
header('location:addproducts.php') ;
}