-
Notifications
You must be signed in to change notification settings - Fork 0
/
addOffer_database.php
70 lines (58 loc) · 2.11 KB
/
addOffer_database.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
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Αποθήκευση στη Βάση την Προσφορά</title>
</head>
<body>
<?php
session_start();
$error_addOffer = "";
$ok_addOffer = "";
$servername = "localhost";
$username = "cyfoodmuseum";
$password = "9m8ESxZD";
$dbname = "cyfoodmuseum";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if (!$conn->set_charset("utf8")) {
printf("Error loading character set utf8: %s\n", $conn->error);
die;
}
parse_url(file_get_contents("php://input"), $_POST);
$CodeProduct = $_SESSION['Code'];
$OldPrice = $_SESSION['price'];
$NewPrice = $_POST['nea_timi'];
$querys = "SELECT * FROM `OFFER` where CodeOfProduct = '$CodeProduct'";
$result=$conn->query($querys);
if($result->num_rows > 0){
$error_addOffer = "Το προϊόν είναι ήδη σε προσφορα!";
$_SESSION['error_addOffer'] = $error_addOffer;
mysqli_close($conn);
header("Location:addOffer.php");
die;
}
$_SESSION['error_addOffer'] = " ";
$sql="INSERT INTO `cyfoodmuseum`.`OFFER` (`CodeOfProduct`,`OldValue`,`NewPrice`) VALUES ('$CodeProduct', '$OldPrice', '$NewPrice');";
$sql1="UPDATE `PRODUCT` SET Price = '$NewPrice' WHERE Code='$CodeProduct'";
$result = $conn->query($sql);
$_SESSION['ok_addOffer'] = " ";
if ($conn->query($sql1) === TRUE){
$ok_addOffer = "Η προσθήκη της προσφοράς ολοκληρώθηκε επιτυχώς!";
$_SESSION['ok_addOffer'] = $ok_addOffer;
mysqli_close($conn);
header("Location:addOffer_selectProduct.php");
die;
}
$error_addOffer = "Η προσθήκη της προσφοράς δεν ολοκληρώθηκε επιτυχώς!";
$_SESSION['error_addOffer'] = $error_addOffer;
mysqli_close($conn);
header("Location:addOffer.php");
die;
?>
</body>
</html>