-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd.php
57 lines (46 loc) · 1.28 KB
/
add.php
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 session_start(); ?>
<?php
if(!isset($_SESSION['valid'])) {
header('Location: login.php');
}
?>
<html>
<head>
<title>Add Data</title>
</head>
<body>
<?php
//including the database connection file
include_once("connection.php");
echo $_SESSION['id'];
if(isset($_POST['Submit'])) {
$name = $_POST['name'];
$qty = $_POST['qty'];
$price = $_POST['price'];
$loginId = $_SESSION['id'];
// checking empty fields
if(empty($name) || empty($qty) || empty($price)) {
if(empty($name)) {
echo "<font color='red'>Name field is empty.</font><br/>";
}
if(empty($qty)) {
echo "<font color='red'>Quantity field is empty.</font><br/>";
}
if(empty($price)) {
echo "<font color='red'>Price field is empty.</font><br/>";
}
//link to the previous page
echo "<br/><a href='javascript:self.history.back();'>Go Back</a>";
} else {
// if all the fields are filled (not empty)
//insert data to database
$result = mysqli_query($mysqli, "INSERT INTO products(name, qty, price, login_id) VALUES('$name','$qty','$price', '$loginId')");
echo $result;
//display success message
echo "<font color='green'>Data added successfully.";
echo "<br/><a href='view.php'>View Result</a>";
}
}
?>
</body>
</html>