-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinsert_Book.php
53 lines (43 loc) · 1.36 KB
/
insert_Book.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
<html>
<body>
<?php
$servername = "localhost";
$username = "root";
$password = "hmysqlg@m31";
$dbname = "mydb";
$db = new mysqli($servername, $username, $password, $dbname);
if($db->connect_errno > 0){
die('Unable to connect to database [' . $db->connect_error . ']');
}
$ISBN = $_POST['ISBN'];
$title = $_POST['title'];
$pubYear = $_POST['pubYear'];
$numpages = $_POST['numpages'];
$pubName = $_POST['pubName'];
$authID = $_POST['authID'];
//Checking to see if given parameters are NULL (Shouldn't the "NOT NULL" in the database be enough?)
if ($ISBN == NULL or $pubYear == NULL or $numpages == NULL or '$title' == NULL or '$pubName' == NULL or $authID == NULL){
echo $ISBN . ' ' . $pubYear . ' ' . $numpages . ' '. $title . ' ' . $pubName . ' ' . $authID .'<br />';
die('Please fill all the fields');
}
$sql1 = <<<SQL
INSERT INTO Book (ISBN, title, pubYear, numpages, pubName)
VALUES($ISBN, '$title', $pubYear, $numpages, '$pubName');
SQL;
$sql2 =<<<SQL
INSERT INTO written_by (ISBN, authID)
VALUES($ISBN, $authID);
SQL;
if(!$result = $db->query($sql1)){
die('There was an error running the query [' . $db->error . ']');
}
if(!$result = $db->query($sql2)){
die('There was an error running the query [' . $db->error . ']');
}
?>
<script>
alert("Succesfull Connection");
window.location = 'insert_Book.html';
</script>
</body>
</html>