forked from priyanka-bitra/BookHub
-
Notifications
You must be signed in to change notification settings - Fork 0
/
BookAdded.php
98 lines (85 loc) · 2.34 KB
/
BookAdded.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
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<style type="text/css">
h1 {color:blue}
</style>
<title>AddBook</title>
<center>
<h1><a href="index.php" style="color: blue;">BookHub</a></h1>
</center>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<?php
//need to take care of the variable StudentId
//here you need to make the book available
//check if the available works
$username=$_GET['username'];
if(isset($_POST['submit'])){
$data_missing=array();
if(empty($_POST['bookName'])){
$data_missing[]='Book Name';
}
else {
$b_name=trim($POST['bookName']);
}
if(empty($_POST['Author'])){
$data_missing[]='Author';
}
else {
$author=trim($POST['Author']);
}
if(empty($_POST['BookEd'])){
$data_missing[]='Book Edition';
}
else {
$b_e=trim($POST['BookEd']);
}
if(empty($data_missing)){
$dbc = mysqli_connect('localhost', 'studentweb', 'turtledove', 'BookHub');
$findStudentId="SELECT studentId FROM user WHERE username='$username'";
$studentId=mysqli_query($dbc,$findStudentId);
$availability='Y';
$query="INSERT INTO Books (Name, Author, Available, BookEd, StudentId, BookId)
VALUES(?,?,?,?,?,NULL)";
$stmt=mysqli_prepare($dbc,$query);
mysqli_stmt_bind_param($stmt,"sssii", $b_name, $author, $availability,
$b_e,$studentId);
mysqli_stmt_execute($stmt);
$affected_rows=mysqli_stmt_affected_rows($stmt);
if($affected_rows==1){
echo 'Book added successfully';
mysqli_stmt_close($stmt);
mysqli_close($dbs);
header('location: http://localhost/~amarbat/Internal/P2/index.php');
}else{
echo 'error occurred<br />';
echo mysqli_error();
mysqli_stmt_close($stmt);
mysqli_close($dbs);
}
}
else{
echo 'You need to enter the following data: <br />';
foreach($data_missing as $missing){
echo "$missing <br />";
}
}
}
?>
<form action="http://localhost/~amarbat/Internal/P2/BookAdded.php">
Enter the details of the book you would like to sell!<br>
Book name:<br>
<input type="text" name="bookName" value=" ">
<br>
Author name:<br>
<input type="text" name="Author" value=" ">
<br>
Book Edition:<br>
<input type="text" name="BookEd" value=" ">
<br>
<input type="submit" name="submit" value="Submit">
</form>
</body>
</html>