卒業研究でPHPとMySQLでホームページを作っています。
データベース(gohandb2)のsyouhinテーブルのjanカラムから検索し、uriageテーブルにレコードを挿入したいのですが色々試行錯誤してみてもわかりません。
発生している問題・エラーメッセージ
PHP
1// $regist = $pdo->prepare("INSERT INTO uriage(id,name, menu, jan,yen,kazu) ; 2// 3// // ぶち込みのルールを決めます(?) 4// // データベースのそれぞれの引き出しに 5// //上で定義した変数の値をぶち込みます 6// 7// $regist->bindParam("id", $id); 8// $regist->bindParam("name", $name); 9// $regist->bindParam("menu", $menu); 10// $regist->bindParam("jan",$jan); 11// $regist->bindParam("yen",$yen); 12// $regist->bindParam("kazu", $kazu); 13// 14// // ぶち込みを実行 15// $regist->execute(array($id,$name, $menu,$jan,$yen,$kazu));
この部分をコメントアウト解除するとサイトすら動かなくなります。
コメントアウトした状態でもsyouhinテーブルのカラムのみからデータを持ってくることになります。
該当のソースコード
PHP
1JAN 2 <!-- <input type = “text” name =“comment“ onchange="jan"/>--> 3 <input id="jan" type="text" > 4 <button href="$list">送信</button> 5 <?php 6 require_once 'dbconnect.php'; 7 // pdoデータベースのshouhinテーブルからカラムを選ぶ準備をして、$list変数のに定義 8 $list = $pdo->prepare("SELECT jan FROM syouhin "); 9 // 取り出し実行 10 $list->execute(); 11 12 // $list->fetch() 13 // データベースのデータはもともとカンマでつなげられているだけの長いCSVデータであり、配列ではない。 14 // そこにfetch()することで、配列化をする。 15 // while文は、TRUEである限りループをする。 16 // while文がfalseになるときは、fetchできなくなったとき、すなわちすべてのデータを配列化し終えたとき。 17 echo " 18 <tr> 19 <th>{$data['id']}</th> 20 <th>{$data['name']}</th> 21 <th>{$data['menu']}</th> 22 <th>{$data['jan']}</th> 23 <th>{$data['yen']}</th> 24 <th>{$data['kazu']}</th> 25 </tr> 26 "; 27 28 29 require_once 'dbconnect.php'; 30 // // pdoデータベースのzaikoテーブルからカラムを選ぶ準備をして、$list変数のに定義 31// $list = $pdo->prepare("SELECT * FROM uriage"); 32 // // 取り出し実行 33 // $list->execute(); 34 35 // 5.在庫データベースのそれぞれのテーブルにデータをぶち込む準備をして、それを$regist変数に定義 36// $regist = $pdo->prepare("INSERT INTO uriage(id,name, menu, jan,yen,kazu) ; 37// 38// // ぶち込みのルールを決めます(?) 39// // データベースのそれぞれの引き出しに 40// //上で定義した変数の値をぶち込みます 41// 42// $regist->bindParam("id", $id); 43// $regist->bindParam("name", $name); 44// $regist->bindParam("menu", $menu); 45// $regist->bindParam("jan",$jan); 46// $regist->bindParam("yen",$yen); 47// $regist->bindParam("kazu", $kazu); 48// 49// // ぶち込みを実行 50// $regist->execute(array($id,$name, $menu,$jan,$yen,$kazu)); 51 52 if ($list) { 53 echo " 54 <table> 55 <thead> 56 <tr> 57 <th>ID</th> 58 <th>商品名</th> 59 <th>カテゴリ</th> 60 <th>JANコード</th> 61 <th>値段</th> 62 <th>数</th> 63 </tr> 64 </thead> 65 66 "; 67 68 while ($data = $list->fetch()) { 69 echo " 70 <tr> 71 <th>{$data['id']}</th> 72 <th>{$data['name']}</th> 73 <th>{$data['menu']}</th> 74 <th>{$data['jan']}</th> 75 <th>{$data['yen']}</th> 76 <th>{$data['kazu']}</th> 77 </tr> 78 "; 79 } 80 } else { 81 echo "エラーです"; 82 } 83 84 echo "</table>"; 85 86 87 ?> 88 <!--<form action="Home.php"> 89 <div class="btn-area6"> 90 <input type="submit" value="ホームへ戻る"> 91 </div> 92 </form> 93 --> 94 <p class="right"> 95 <a class="btn-style-link" input type="reset"> 96 リセット 97 </a> 98 99 <a class="btn-style-link" href="kaikei.php"> 100 会計 101 </a> 102 </p> 103 104 <!--<form action="product_registation.php"> 105 <div class="btn-area7"> 106 <input type="submit" value="続けて登録"> 107 </div> 108 </form> 109 --> 110 111 <style type="text/css"> 112 thead,tbody{ 113 display: block; 114 background-color:gray; 115 } 116 tbody { 117 overflow-x: hidden; 118 overflow-y: scroll; 119 height: 750px; 120 } 121 th,td{ 122 width:150px; 123 background-color:white; 124 } 125 /*tr{ 126 background-color:#eed4e8; 127 }*/ 128 table{ 129 margin:0 auto; 130 } 131 132 a.btn-style-link{ 133 display: inline-block; 134 padding: 16px 24px; 135 text-decoration: none; 136 border: 1px; 137 background: #e0505c; 138 color: #fff; 139 box-shadow: 0px 2px 4px #575; 140 font-weight:bold; 141 } 142 a.btn-area{ 143 display: inline-block; 144 padding: 16px 24px; 145 text-decoration: none; 146 border: 1px; 147 background: #e0505c; 148 color: #fff; 149 box-shadow: 0px 2px 4px #575; 150 font-weight:bold; 151 } 152 .right{ 153 text-align:right; 154 padding:30px 250px; 155 } 156 /*.right2{ 157 text-align:right; 158 margin:auto; 159 }*/
補足情報(FW/ツールのバージョンなど)
MAMPを使用しております。
エディターはPHP Stormです。