皆様いつもお世話になっております。
実行環境は以下の通りです。
PHP:7.2.1
phpMyAdmin:4.7.7
MySQL:5.6.38
PHPを使って増減させたいのですが、$_POST['code']に値がうまく入らず、エラーが出てしまいます。
PHP
1<?php 2 3function accessSQL(){ 4 $user = "root"; 5 $pass = "root"; 6 $dbh = new PDO('mysql:host=localhost;dbname=hozon;charset=utf8', $user, $pass); 7 return $dbh; 8} 9 10try { 11 $dbh = accessSQL(); 12 $stmt = $dbh->prepare("SELECT id, code, prod_name, mount, category, end_date from hozon where id = 56"); 13 $stmt->execute(); 14 $value_array = $stmt->fetchALL(); 15 foreach ($value_array as $value) { 16 $value['code']; 17 $value['prod_name']; 18 $value['mount']; 19 } 20 }catch (PDOException $e){ 21 echo $e->getMessage(); 22 } 23 24 25if (isset($_POST['change'])){ 26 echo 'new_mount is : '.$_POST['new_mount'];//テスト 27 echo 'code is : '.$_POST['code'];//テスト:ここの$_POST変数にcodeが代入されない 28 try{$dbh = accessSQL(); 29 $stmt = $dbh->prepare("update hozon set mount = :mount where code = :code"); 30 $stmt -> bindParam(':mount', $_POST['new_mount'],PDO::PARAM_STR); 31 $stmt -> bindParam(':code',$_POST['code'], PDO::PARAM_STR); //ここの$_POST変数にコードが代入されない 32 $stmt -> execute(); 33 }catch (PDOException $e){ 34 echo $e->getMessage(); 35 } 36} 37 38if (isset($_POST['cancel'])){ 39 [header('Location:./index.php')]; 40 exit(); 41} 42?> 43<!doctype html> 44<html lang="ja"> 45<head> 46 <meta charset="UTF-8"> 47 <meta http-equiv="X-UA-Compatible" content="ie=edge"> 48 <!--Import materialize.css--> 49 <link type="text/css" rel="stylesheet" href="css/materialize.min.css" media="screen,projection"/> 50 <link type="text/css" rel="stylesheet" href="css/base.css" media="screen,projection"/> 51 <title>保存期限管理システム</title> 52</head> 53<form action="update.php" method="post"> 54 <div class="row input-field"> 55 <div class="col s2"> 56 <label> </label> 57 <input type="text" name="code" placeholder="商品番号" value="<?php echo $value['code'];?>" disabled> 58 </div> 59 <div class="col s5"> 60 <label> </label> 61 <input type="text" name="prod_name" placeholder="商品名" value="<?php echo $value['prod_name']; ?>" disabled> 62 </div> 63 <div class="col s5"> 64 <label>*個数(半角数字で入力してください)</label> 65 <input type="number" name="new_mount" placeholder="個数" min="1" value="<?php echo $value['mount']; ?>" required> 66 </div> 67 68 <div class="row"> 69 <input type="submit" name="change" value="登録" class="regist btn btn-large"> 70 <input type="submit" name="cancel" value="キャンセル" class="btn-large cancel"> 71 </div> 72 </div> 73</form> 74
どうしたら$_POST['code']に値が入るようになるでしょうか?アドバイスとご教授のほどよろしくお願いします。
回答4件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/05/11 04:02