-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsellTextBooksScript.html
111 lines (94 loc) · 3.15 KB
/
sellTextBooksScript.html
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
<!--this is where we should use firebase connection-->
<!--<?php
//session_start();
?>-->
<script src="https://www.gstatic.com/firebasejs/4.6.2/firebase.js"></script>
<script>
// Initialize Firebase
var config = {
apiKey: "AIzaSyAKAvtSqE25LzqCWv4PzPlHuC9a-UadF7U",
authDomain: "studyswapwebsite.firebaseapp.com",
databaseURL: "https://studyswapwebsite.firebaseio.com",
projectId: "studyswapwebsite",
storageBucket: "studyswapwebsite.appspot.com",
messagingSenderId: "271728404472"
};
firebase.initializeApp(config);
</script>
<?php
session_start();
//Address error handling
ini_set('display_errors', 1);
//error_reporting(E_ALL & E_NOTICE);
//Attempt to connect
if($connection=@mysql_connect('localhost', 'bcratty1', 'BJamesC32')){
//print '<p>Successfully connected to MySQL.</p>';
}else{
die('<p>Could not connect to MySQL because:<b>'.mysql_error().'</b></p>');
}
if(@mysql_select_db("tshay1DB", $connection)){
//print '<p> The tshay1DB database has been selected</p>';
}else{
die('<p>Could not select the tshay1DB database because:<b>'.mysql_error().'</b></p>');
}
$author=$_POST['author'];
$title=$_POST['title'];
$ISBN=$_POST['isbn'];
$year=$_POST['year'];
$edition=$_POST['edition'];
$condition=$_POST['condition'];
$price=$_POST['price'];
if(isset($_SESSION['userID']))
{
$id = $_SESSION['userID'];
}
if (isset($_SESSION['loggedin']) && $_SESSION['loggedin'] == true)
{
$query="INSERT INTO `books`(`Author`, `Title`, `ISBN`, `Year`, `Edition`) VALUES ('$author','$title','$ISBN', '$year', '$edition')";
if($r=mysql_query($query))
{
echo $_SESSION['username'] . "<br>";
echo "Successfully inserted a book!";
$updateQuantityQuery="UPDATE books SET quantity = quantity + 1 WHERE ISBN = '$ISBN'";
if($r=mysql_query($updateQuantityQuery))
{
echo "updated quantity!";
}
$addToSellingQuery="INSERT INTO `selling`(`sellPrice`, `condition`, `isbnSelling`, `userIDSelling`) VALUES ('$price','$condition','$ISBN','$id')";
if($r=mysql_query($addToSellingQuery))
{
echo "inserted into selling!";
}
}
else
{
//die('<p>Could not insert. ISBN already in books table! :<b>'.mysql_error().'</b></p>');
echo 'ISBN already in books table, so it has not been inserted there.</p>';
$updateQuantityQuery="UPDATE books SET quantity = quantity + 1 WHERE ISBN = '$ISBN'";
if($r=mysql_query($updateQuantityQuery))
{
echo "updated quantity!";
}
$addToSellingQuery="INSERT INTO `selling`(`sellPrice`, `condition`, `isbnSelling`, `userIDSelling`) VALUES ('$price','$condition','$ISBN','$id')";
if($r=mysql_query($addToSellingQuery))
{
echo "inserted into selling!";
}
}
}
else
{
echo "You must be logged in to sell a book!";
}
echo '. <a href="sellTextBooks.html">Go back</a>';
/*$query="SELECT * FROM student";
if($r=mysql_query($query)){
//echo "dummy1";
while($row=mysql_fetch_array($r)){
// echo "dummy 222 \n";
print "<p>
{$row['id']};
{$row['name']}; </p>\n";
}
}*/
?>