-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbooks.php
170 lines (140 loc) · 4.07 KB
/
books.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
class Books{
var $id;
var $bookTitle;
var $authorName;
var $publisherName;
var $edition;
var $ISBN_num;
var $price;
var $numCopies;
var $servername = "localhost";
var $username = "root";
var $password = "";
var $dbname = "libraryManagement";
var $conn1 = "";
function setId($id)
{
$this->id = $id;
}
function setBookTtile($bookTitle)
{
$this->bookTitle = $bookTitle;
}
function setAuthorName($authorName)
{
$this->authorName = $authorName;
}
function setPublisherName($publisherName)
{
$this->publisherName = $publisherName;
}
function setEdition($edition)
{
$this->edition = $edition;
}
function setISBN_num($ISBN_num)
{
$this->ISBN_num = $ISBN_num;
}
function setPrice($price)
{
$this->price = $price;
}
function setNumCopies($numCopies)
{
$this->numCopies = $numCopies;
}
function getId()
{
echo $this->id ."<br/>";
}
function getBookTtile()
{
echo $this->bookTitle ."<br/>";
}
function getAuthorName()
{
echo $this->authorName ."<br/>";
}
function getPublisherName()
{
echo $this->publisherName ."<br/>";
}
function getEdition()
{
echo $this->edition ."<br/>";
}
function getISBN_num()
{
echo $this->ISBN_num ."<br/>";
}
function getPrice()
{
echo $this->price ."<br/>";
}
function getNumCopies()
{
echo $this->numCopies ."<br/>";
}
function insertBookDetails()
{
$conn = mysqli_connect($this->servername, $this->username, $this->password, $this->dbname);
mysql_select_db($this->dbname);
//Comment Code After Inserting Record On Load
$sql = "INSERT INTO Book (bookTitle, author, publisher, edition, ISBN_no, price, NumOfCopies)
VALUES ('How Life Learned to Live: Adaptation in Nature','Ronald S. Calinger','MIT Press','1','ISBN 978-0-262-20045-5','100',10),
('Physics in Molecular Biology','Frank H','Cambridge University Press','3','ISBN 0-521-84419-3','70',10),
('The Early Universe','Jerrold Grossman','Addison Wesley','5','ISBN 0-201-11604-9','72',10),
('Methods of theoretical physics','Linda Pulsinellir','New York: McGraw-Hill','4','ISBN 978-0-07-043316-8','60',10)";
// $sql = "INSERT INTO Book (bookTitle, author, publisher, edition, ISBN_no, price, NumOfCopies)
// VALUES ('$this->bookTitle', '$this->authorName','$this->publisherName','$this->edition','$this->ISBN_num','$this->price',$this->numCopies)";
if ($conn->query($sql) === TRUE) {
//echo "New record created successfully";
} else {
//echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
function updateBookDetails($id)
{
$conn = mysqli_connect($this->servername, $this->username, $this->password, $this->dbname);
mysql_select_db($this->dbname);
$sql = "UPDATE Book SET
bookTitle = '$this->bookTitle',author = '$this->authorName',publisher = '$this->publisherName',edition ='$this->edition',
ISBN_no ='$this->ISBN_num',price = '$this->price',NumOfCopies = $this->numCopies
WHERE bookID= $id";
if ($conn->query($sql) === TRUE) {
//echo "New record created successfully";
} else {
//echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
function updateBookQuantity($id,$updatedBookCopies){
$conn = mysqli_connect($this->servername, $this->username, $this->password, $this->dbname);
mysql_select_db($this->dbname);
$sql = "UPDATE Book SET
NumOfCopies = $updatedBookCopies
WHERE bookID= $id";
if ($conn->query($sql) === TRUE) {
//echo "New record created successfully";
} else {
//echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
}
function deleteBookDetails($id){
$conn = mysqli_connect($this->servername, $this->username, $this->password, $this->dbname);
mysql_select_db($this->dbname);
// sql to delete a record
$sql = "DELETE FROM Book WHERE bookID=$id";
if ($conn->query($sql) === TRUE) {
// echo "Record deleted successfully";
} else {
// echo "Error deleting record: " . $conn->error;
}
$conn->close();
}
}
?>