本を予約する機能を作成していますが、PDOのステートメントを含むoop関数が作動せず困っています。
特に、insertとupdateのところが作動しません。どうしてこんな事が起こるのでしょうか?
作成したコードは、下記になります。
[bookReserve.php]
lang
1<?php 2session_start(); 3include_once "../styles/header-menu-out.php"; 4include_once "dbconnection.php"; 5 6function __autoload($class){ 7include_once("../main/".$class.".php");} 8 9$code = new codex_books(); 10 11$sname = $_POST['名前']; 12$sid = $_POST['sid']; 13$id = $_POST['id']; 14$title = $_POST['タイトル']; 15$author = $_POST['作者']; 16$isbn = $_POST['isbn']; 17$publisher = $_POST['出版社']; 18$language = $_POST['言語']; 19$genre = $_POST['ジャンル']; 20$quantity = $_POST['数量']; 21$date_to_be_borrow = $_POST['貸し出し予定日']; 22 23$result = $code->bookreserve($id,"book_info"); 24 25if(isset($_POST['予約'])) 26{ 27 foreach($result as $row) 28 { 29 echo $oldstock=$row['数量']; 30 } 31 32 echo $newstock = $oldstock-1; 33 34 $code->minusbookreserve($quantity, $newstock,"book_info"); 35 $code->insertbookreserve($sid,$sname,$title,$author,$isbn,$publisher,$language,$genre,$quantity,$date_to_be_borrow,"reserve_list"); 36 // echo "<script type='text/javascript'>alert('Successfully Reserved.');window.location='bookReservelist.php';</script>"; 37} 38else { 39 echo "<script type='text/javascript'>alert('何かうまく作動しませんでした。');window.location='bookReservelist.php';</script>"; 40} 41 42?>
[codex_books.php]
lang
1<?php 2public function minusbookreserve($quantity, $newstock, $table) 3{ 4 $q = "UPDATE $table SET quantity = ':newstock' where book_title = ':book_title'"; 5 $stmt = $this->con->prepare($q); 6 $stmt->execute(array(':newstock'=>$newstock, ':quantity'=>$quantity)); 7 if($stmt){ 8 return true; 9 } 10 else { 11 return false; 12 } 13} 14 15public function insertbookreserve($sid,$sname,$title,$author,$isbn,$publisher,$language,$genre,$quantity,$date_to_be_borrow,$table) 16{ 17 $q = "INSERT INTO $table SET sid= :sid ,sname=:sname,title=:title,author=:author,isbn=:isbn,publisher=:publisher,language=:language, genre=:genre, quantity=:quantity, date_to_be_borrow=:date_to_be_borrow"; 18 $stmt = $this->con->prepare($q); 19 $stmt->execute(array(':sid'=>$sid,':sname'=>$sname,':title'=>$title,':author'=>$author,':isbn'=>$isbn,':publisher'=>$publisher,':language'=>$language, ':genre'=>$genre,':quantity'=>$quantity,':date_to_be_borrow'=>$date_to_be_borrow)); 20 return true; 21} 22?>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。