-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconnect.php
More file actions
84 lines (68 loc) · 1.9 KB
/
connect.php
File metadata and controls
84 lines (68 loc) · 1.9 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
<?php
session_start();
$servername = "localhost";
$username = "root";
$password = "";
$db="stock";
// Create connection
$conn = new mysqli($servername, $username, $password, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$id=0;
$designation="";
$price="";
$quantity="";
$update=false;
if(isset($_POST["save"])){
$des=$_POST['designation'];
$pr = $_POST['price'];
$qnt = $_POST['quantity'];
$conn-> query("INSERT INTO Article (designation, price, quantity)
VALUES ('$des', $pr, $qnt)")
or die($conn->error($conn));
$_SESSION["message"] = "Article added successfully.";
$_SESSION["msg_type"] = "success";
$conn->close();
header("location: index.php");
}
if(isset($_GET["delete"])){
$id=$_GET["delete"];
$conn-> query("DELETE from Article where id =$id") or die($conn->error());
$_SESSION["message"] = "Article deleted successfully.";
$_SESSION["msg_type"] = "danger";
$conn->close();
header("location: index.php");
}
if(isset($_GET["add"])){
$id=0;
$designation = "";
$price = 0;
$quantity = 0;
$update=false;
header("location: index.php");
}
if(isset($_GET["edit"])){
$id=$_GET['edit'];
$result= $conn -> query("SELECT * from Article where id=$id") or die($conn->error());
if(count($result)==1){
$row = $result->fetch_array();
$designation = $row["designation"];
$price = $row["price"];
$quantity = $row["quantity"];
$update=true;
}
}
if(isset($_POST["update"])){
$id=$_POST["id"];
$designation=$_POST["designation"];
$price=$_POST["price"];
$quantity=$_POST["quantity"];
$conn-> query("UPDATE Article SET designation='$designation', price=$price, quantity=$quantity where id=$id")
or die($conn->error());
$_SESSION['message'] = "Article infos has been updated";
$_SESSION['msg_type'] = "warning";
header("location : index.php");
}
?>