-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcart_update.php
More file actions
141 lines (115 loc) · 4.14 KB
/
Copy pathcart_update.php
File metadata and controls
141 lines (115 loc) · 4.14 KB
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
<?php
$id = $_GET["id"];
if ($id == NULL){
header( "Location: index.php" ) ;
exit;
}
/* 本の情報を取得 */
$json = file_get_contents("https://www.googleapis.com/books/v1/volumes/$id?key=AIzaSyBczORlfI6MEmYnkTFwP5au6rq_oo4h92s");
$results = json_decode($json, TRUE);
$title = $results[volumeInfo][title]." ".$results[volumeInfo][subtitle];
$publishedDate = $results[volumeInfo][publishedDate];
$publisher = $results[volumeInfo][publisher];
$imageLink = $results[volumeInfo][imageLinks][smallhumbnail];
foreach ($results[volumeInfo][industryIdentifiers] as $i => $identifier) {
if ($identifier[type] === "ISBN_10") {
$isbn10 = $identifier[identifier];
}
if ($identifier[type] === "ISBN_13") {
$janCode = $identifier[identifier];
}
}
foreach($results[volumeInfo][authors] as $i => $author) {
$authors = $authors.$author." ";
}
$authors = rtrim($authors,' ');
if ($results[saleInfo][listPrice][amount] == NULL) {
$listPrice = "(注文確定後にお知らせ)";
} else {
$listPrice = $results[saleInfo][listPrice][amount];
}
if ($results[volumeInfo][imageLinks][thumbnail] == NULL){
$imageLink = "img/noimage.png";
} else {
$imageLink = $results[volumeInfo][imageLinks][thumbnail];
}
/* データベースに接続 */
$dsn = 'mysql:dbname=websysb7;host=ja-cdbr-azure-east-a.cloudapp.net;charset=utf8';
$username = 'b3a7f491a4430f';
$password = '0a1e66e0';
$pdo = new PDO($dsn, $username, $password);
/* カートに追加する本をデータベースから検索、無ければ追加 */
$sql = "SELECT count(*) FROM Item WHERE JANCode='$janCode'";
$stmt = $pdo->query($sql);
$count = $stmt->fetchColumn();
if ($count == 0) {
$sql = "INSERT INTO Item(JANCode,Price) VALUES(:JANCode,:Price)";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':JANCode',$janCode);
if ($results[saleInfo][listPrice][amount] == NULL) {
$stmt->bindValue(':Price',NULL,PDO::PARAM_NULL);
} else {
$stmt->bindParam(':Price',$listPrice);
}
$stmt->bindParam(':ProductName',$title);
$stmt->execute();
$sql = "INSERT INTO Book VALUES(:JANCode,:BookTitle,:Writer,:Publisher,:GoogleID)";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':JANCode',$janCode);
$stmt->bindParam(':BookTitle',$title);
$stmt->bindParam(':Writer',$authors);
$stmt->bindParam(':Publisher',$publisher);
$stmt->bindParam(':GoogleID',$id);
$stmt->execute();
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="stylesheet" href="css/cart.css">
<link rel="icon" href="img/favicon.ico">
<title>O書店</title>
</head>
<body>
<header>
<h1><a href="index.php">O書店</a></h1>
<span>Web注文機能を使うためには、ログインしてください</span>
<a id="login" href="">ログイン</a>
</header>
<form id="search" method="get" action="search.php">
<input name="q" type="search" placeholder="書籍を検索">
<input type="submit" value="">
</form>
<div id="main">
<div id="cart">
<section>
<h2>カートに追加しました</h2>
<img alt="<?php echo $title ?>" src="<?php echo $imageLink ?>">
<h3><?php echo $title ?></h3>
<p class="publishedDate"><?php echo $publishedDate ?></p>
<p><?php echo $authors ?></p>
<p class="price">¥ <?php echo $listPrice ?></p>
</section>
<section>
<h2>カートに入っている商品</h2>
<img alt="<?php echo $title ?>" src="<?php echo $imageLink ?>">
<h3><?php echo $title ?></h3>
<p class="publishedDate"><?php echo $publishedDate ?></p>
<p><?php echo $authors ?></p>
<p class="price">¥ <?php echo $listPrice ?></p>
</section>
</div>
<section id="nav">
<p><a class="button" href="order.php?id=<?php echo $id ?>">注文を確定する</a></p>
<p><a class="button_c" href="">買い物を続ける</a></p>
</section>
</div>
<footer>
<a href="">規約</a>
<a href="">プライバシー</a>
<a href="">店舗</a>
</footer>
</body>
</html>