PHP SQLはデータを更新しません -- php フィールド と html フィールド と sql-update フィールド 関連 問題

PHP SQL won't update the data












1
vote

問題

日本語

2015年6月23日現在の更新

更新クエリはまだ機能していません。 Rene Krossからアドバイスを受講し、いくつかのコードのクリーンアップをして、いくつかの部分の欠落セミコロンなどにつまずいたが、更新クエリはまだ機能していません。

これはadminupdate.php

です

 <コード> <?php       require 'Connect.php';     $staffID = null;   if ( !empty($_GET['staffID'])) {    $staffID = $_REQUEST['staffID'];   }      if ( null==$staffID ) {    header("Location: ManageAdministrator.php");   }      if ( !empty($_POST)) {    // keep track validation errors        $adminNameError = null;    $emailError = null;    $SKGError = null;    $ExtnError = null;          // keep track post values        $adminName = $_POST['adminName'];    $email = $_POST['email'];    $SKG = $_POST['SKG'];    $Extn = $_POST['Extn'];          // validate input    $valid = true;        if (empty($adminName)){     $adminNameError = "Please enter Administrator Name";     $valid = false;    }        if (empty($email)) {     $emailError = 'Please enter Email Address';     $valid = false;    } else if ( !filter_var($email,FILTER_VALIDATE_EMAIL) ) {     $emailError = 'Please enter a valid Email Address';     $valid = false;    }        if (empty($SKG)) {     $SKGError = 'Please choose SKG';     $valid = false;    }    if(empty($Extn)){     $ExtnError = "Please enter Extension Number";     $valid = false;    }            // update data    if ($valid) {     $pdo = Database::connect();     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);     $sql = "UPDATE admin set adminName ='$adminName', email ='$email', SKG ='$SKG', Extn ='$Extn' WHERE staffID = '$staffID'";     $q = $pdo->prepare($sql);     $q->execute(array($staffID,$adminName,$email,$SKG,$Extn));     Database::disconnect();     header("Location: ManageAdministrator.php");    }   } else {    $pdo = Database::connect();    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);    $sql = "SELECT * FROM admin where staffID = ?";    $q = $pdo->prepare($sql);    $q->execute(array($staffID));    $data = $q->fetch(PDO::FETCH_ASSOC);    $adminName = $data['adminName'];    $email = $data['email'];    $SKG = $data['SKG'];    $Extn = $data['Extn'];    $password = $data['password'];    Database::disconnect();   }  ?>    <!DOCTYPE html>  <html lang="en">   <head>     <title>Update Administrator</title>        <meta charset="utf-8">        <meta http-equiv="X-UA-Compatible" content="IE=edge">        <meta name="viewport" content="width=device-width, initial-scale=1">        <meta name="description" content="">        <meta name="author" content="Capability Management">        <!-- CSS External Link -->        <link href="css/bootstrap.min.css" rel="stylesheet">        <link href="css/sb-admin.css" rel="stylesheet">        <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">   </head>     <body>     <script src="js/jquery.js"></script>        <script src="js/bootstrap.min.js"></script>            <div id="wrapper">         <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">           <div class="navbar-header">              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">                 <span class="sr-only">Toggle navigation</span>                      <span class="icon-bar"></span>                      <span class="icon-bar"></span>                      <span class="icon-bar"></span>              </button>              <a class="navbar-brand" href="HomePage.php"><b> Training Log Database </b></a>            </div>              <ul class="nav navbar-right top-nav">                   <li class="dropdown">                       <!-- PHP REFER LOGIN NAME-->                        <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> M Farhan M Fazli <b class="caret"></b></a>                         <ul class="dropdown-menu">                              <li>                                  <a href="MyProfile.php"><i class="fa fa-fw fa-user"></i> Profile</a>                             </li>                             <li class="divider"></li>                            <li>                              <!-- PHP LOGOUT FUNCTION -->                              <a href="LoginPage.html"><i class="fa fa-fw fa-power-off"></i> Log Out</a>                          </li>                      </ul>                  </li>              </ul>              <!-- Sidebar Menu Items start here -->              <div class="collapse navbar-collapse navbar-ex1-collapse">                  <ul class="nav navbar-nav side-nav">                      <li>                          <a href="HomePage.php"><i class="fa fa-fw fa-dashboard"></i> Home</a>                      </li>                      <li>                          <a href="ManageAdministrator.php"><i class="fa fa-fw fa-bar-chart-o"></i> Manage Administrator</a>                      </li>                      <li>                        <!-- Add new pages here -->                          <a href="#"><i class="fa fa-fw fa-bar-chart-o"></i> Manage Staff</a>                      </li>                      <li>                          <a href="javascript:;" data-toggle="collapse" data-target="#demo"><i class="fa fa-fw fa-edit"></i> Manage Training<i class="fa fa-fw fa-caret-down"></i></a>                          <ul id="demo" class="collapse">                              <li>                                  <a href="TrainingList.php">Training Information</a>                              </li>                              <li>                                  <a href="#">TBA</a>                              </li>                                                      </ul>                      </li>                      <li>                          <a href="javascript:;" data-toggle="collapse" data-target="#demo1"><i class="glyphicon glyphicon-wrench"></i>  Tools for Administrator<i class="fa fa-fw fa-caret-down"></i></a>                          <ul id="demo1" class="collapse">                            <li><a href="#"> Add News </a></li>                            <li><a href="#"> Add Announcement </a></li>                            <li><a href="#"> Search News</a> </li>                            <li><a href="#"> Search Announcement </a></li>                            <li><a href="#"> View My Post </a></li>                          </ul>                      </li>                      <li>                          <a href="#"><i class="glyphicon glyphicon-info-sign"></i> About</a>                      </li>                      <li>                          <a href="#"><i class="glyphicon glyphicon-question-sign"></i> FAQs</a>                      </li>                                                  </div>              <!-- /.navbar-collapse -->          </nav>          <div id="page-wrapper">           <div class="container-fluid">            <div class="row col-lg-12">             <h2 class="page-header"> Update Administrator Account </h2>             <div class="row col-lg-12">              <h3> Administrator details </h3>              <div class="row col-lg-12">          <form class="form-horizontal form-group" action="adminUpdate.php?id=<?php echo $staffID?>" method="post">              <!-- <div class="form-group col-lg-12 <?php echo !empty($staffIDError)?'error':'';?>">              <label>Administrator Staff ID</label>                <input class="form-control" name="staffID" type="text" value="<?php echo !empty($staffID)?$staffID:'';?>">                  <?php if (!empty($staffIDError)): ?>                    <span class="help-inline"><?php echo $staffIDError;?></span>                   <?php endif; ?>             </div>-->              <div class="form-group col-lg-12 <?php echo !empty($adminNameError)?'error':'';?>">              <label>Administrator Name</label>                <input class="form-control" name="adminName" type="text" value="<?php echo !empty($adminName)?$adminName:'';?>">                  <?php if (!empty($adminNameError)): ?>                    <span class="help-inline"><?php echo $adminNameError;?></span>                   <?php endif; ?>            </div>              <div class="form-group col-lg-12 <?php echo !empty($emailError)?'error':'';?>">              <label>Administrator Email</label>                <input class="form-control" name="email" type="text" value="<?php echo !empty($email)?$email:'';?>">                  <?php if (!empty($emailError)): ?>                    <span class="help-inline"><?php echo $emailError;?></span>                   <?php endif; ?>            </div>            <div class="form-group col-lg-12 <?php echo !empty($ExtnError)?'error':'';?>">             <label> Extension Number </label>              <input class="form-control" name="Extn" type="text" value="<?php echo !empty($Extn)?$Extn:'';?>">               <?php if (!empty($ExtnError)): ?>                <span class="help-inline"><?php echo $ExtnError;?></span>               <?php endif; ?>             </label>            </div>            <div class="form-group col-lg-12 <?php echo !empty($SKGError)?'error':'';?>">              <label>SKG</label>                <select class="form-control" name="SKG" value="<?php echo !empty($SKG)?$SKG:'';?>">                   <option> SKG 09 </option>                   <option> SKG 18 </option>                   <option> SKG 20 </option>                   <option> SKG 16 </option>                   <option> SKG 11 </option>                   <option> SKG 13 </option>                   <option> SKG 14 </option>                   <option> SKG 12 </option>                   <option> SKG 15 </option>                   <option> SKG 10 </option>                   <option> SKG 25 </option>                  </select>                  <?php if (!empty($SKGError)): ?>                    <span class="help-inline"><?php echo $SKGError;?></span>                   <?php endif; ?>            </div>             <!-- <div class="form-group col-lg-12 <?php echo !empty($passwordError)?'error':'';?>">              <label>Password</label>                <input type="password" name="password" id="password" class="form-control" placeholder="Password" value="<?php echo !empty($password)?$password:'';?>">                  <?php if (!empty($passwordError)): ?>                    <span class="help-inline"><?php echo $passwordError;?></span>                   <?php endif; ?> -->            </div>            <div class="form-actions col-lg-12">              <button type="submit" class="btn btn-success">Update</button>              <a class="btn btn-default" href="ManageAdministrator.php">Back</a>            </div>                 </form>                </div>             </div>            </div>           </div>          </div>      </div><!--wrap-->    </body>  </html>       

これはconnect.php

です

 <コード> <?php  class Database   {   private static $dbName = 'tlad' ;    private static $dbHost = 'localhost' ;   private static $dbUsername = 'root';   private static $dbUserPassword = '';      private static $cont  = null;      public function __construct() {    exit('Init function is not allowed');   }      public static function connect()   {      // One connection through whole application         if ( null == self::$cont )         {                try           {            self::$cont =  new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword);            }          catch(PDOException $e)           {            die($e->getMessage());            }         }          return self::$cont;   }      public static function disconnect()   {    self::$cont = null;   }  }  ?>  

これは私のテーブルです: イメージの説明を入力して

前述したように、この更新機能を除いて、読み取り、作成、削除機能が機能しています。

注意:私は彼のテンプレートが働いていたが、コードが働いていない間は、CRUDデータベースを作成するためのチュートリアルに従いました。更新テンプレートのチュートリアルのコード:

 <コード> <?php       require 'database.php';     $id = null;   if ( !empty($_GET['id'])) {    $id = $_REQUEST['id'];   }      if ( null==$id ) {    header("Location: index.php");   }      if ( !empty($_POST)) {    // keep track validation errors    $nameError = null;    $emailError = null;    $mobileError = null;        // keep track post values    $name = $_POST['name'];    $email = $_POST['email'];    $mobile = $_POST['mobile'];        // validate input    $valid = true;    if (empty($name)) {     $nameError = 'Please enter Name';     $valid = false;    }        if (empty($email)) {     $emailError = 'Please enter Email Address';     $valid = false;    } else if ( !filter_var($email,FILTER_VALIDATE_EMAIL) ) {     $emailError = 'Please enter a valid Email Address';     $valid = false;    }        if (empty($mobile)) {     $mobileError = 'Please enter Mobile Number';     $valid = false;    }        // update data    if ($valid) {     $pdo = Database::connect();     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);     $sql = "UPDATE customers  set name = ?, email = ?, mobile =? WHERE id = ?";     $q = $pdo->prepare($sql);     $q->execute(array($name,$email,$mobile,$id));     Database::disconnect();     header("Location: index.php");    }   } else {    $pdo = Database::connect();    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);    $sql = "SELECT * FROM customers where id = ?";    $q = $pdo->prepare($sql);    $q->execute(array($id));    $data = $q->fetch(PDO::FETCH_ASSOC);    $name = $data['name'];    $email = $data['email'];    $mobile = $data['mobile'];    Database::disconnect();   }  ?>      <!DOCTYPE html>  <html lang="en">  <head>      <meta charset="utf-8">      <link   href="css/bootstrap.min.css" rel="stylesheet">      <script src="js/bootstrap.min.js"></script>  </head>    <body>      <div class="container">               <div class="span10 offset1">          <div class="row">           <h3>Update a Customer</h3>          </div>                  <form class="form-horizontal" action="update.php?id=<?php echo $id?>" method="post">         <div class="control-group <?php echo !empty($nameError)?'error':'';?>">           <label class="control-label">Name</label>           <div class="controls">              <input name="name" type="text" value="<?php echo !empty($name)?$name:'';?>">              <?php if (!empty($nameError)): ?>               <span class="help-inline"><?php echo $nameError;?></span>              <?php endif; ?>           </div>         </div>         <div class="control-group <?php echo !empty($emailError)?'error':'';?>">           <label class="control-label">Email Address</label>           <div class="controls">              <input name="email" type="text" value="<?php echo !empty($email)?$email:'';?>">              <?php if (!empty($emailError)): ?>               <span class="help-inline"><?php echo $emailError;?></span>              <?php endif;?>           </div>         </div>         <div class="control-group <?php echo !empty($mobileError)?'error':'';?>">           <label class="control-label">Mobile Number</label>           <div class="controls">              <input name="mobile" type="text" value="<?php echo !empty($mobile)?$mobile:'';?>">              <?php if (!empty($mobileError)): ?>               <span class="help-inline"><?php echo $mobileError;?></span>              <?php endif;?>           </div>         </div>         <div class="form-actions">          <button type="submit" class="btn btn-success">Update</button>          <a class="btn" href="index.php">Back</a>        </div>       </form>      </div>            </div> <!-- /container -->    </body>  </html>  
英語

Update as of 23rd June 2015

The update query still not working. Took an advice from Rene Kross and made some code cleanup and stumbled upon a few part missing semicolons and etc however the update query are still not working.

Here's the adminUpdate.php

<?php       require 'Connect.php';     $staffID = null;   if ( !empty($_GET['staffID'])) {    $staffID = $_REQUEST['staffID'];   }      if ( null==$staffID ) {    header("Location: ManageAdministrator.php");   }      if ( !empty($_POST)) {    // keep track validation errors        $adminNameError = null;    $emailError = null;    $SKGError = null;    $ExtnError = null;          // keep track post values        $adminName = $_POST['adminName'];    $email = $_POST['email'];    $SKG = $_POST['SKG'];    $Extn = $_POST['Extn'];          // validate input    $valid = true;        if (empty($adminName)){     $adminNameError = "Please enter Administrator Name";     $valid = false;    }        if (empty($email)) {     $emailError = 'Please enter Email Address';     $valid = false;    } else if ( !filter_var($email,FILTER_VALIDATE_EMAIL) ) {     $emailError = 'Please enter a valid Email Address';     $valid = false;    }        if (empty($SKG)) {     $SKGError = 'Please choose SKG';     $valid = false;    }    if(empty($Extn)){     $ExtnError = "Please enter Extension Number";     $valid = false;    }            // update data    if ($valid) {     $pdo = Database::connect();     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);     $sql = "UPDATE admin set adminName ='$adminName', email ='$email', SKG ='$SKG', Extn ='$Extn' WHERE staffID = '$staffID'";     $q = $pdo->prepare($sql);     $q->execute(array($staffID,$adminName,$email,$SKG,$Extn));     Database::disconnect();     header("Location: ManageAdministrator.php");    }   } else {    $pdo = Database::connect();    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);    $sql = "SELECT * FROM admin where staffID = ?";    $q = $pdo->prepare($sql);    $q->execute(array($staffID));    $data = $q->fetch(PDO::FETCH_ASSOC);    $adminName = $data['adminName'];    $email = $data['email'];    $SKG = $data['SKG'];    $Extn = $data['Extn'];    $password = $data['password'];    Database::disconnect();   }  ?>    <!DOCTYPE html>  <html lang="en">   <head>     <title>Update Administrator</title>        <meta charset="utf-8">        <meta http-equiv="X-UA-Compatible" content="IE=edge">        <meta name="viewport" content="width=device-width, initial-scale=1">        <meta name="description" content="">        <meta name="author" content="Capability Management">        <!-- CSS External Link -->        <link href="css/bootstrap.min.css" rel="stylesheet">        <link href="css/sb-admin.css" rel="stylesheet">        <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet" type="text/css">   </head>     <body>     <script src="js/jquery.js"></script>        <script src="js/bootstrap.min.js"></script>            <div id="wrapper">         <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">           <div class="navbar-header">              <button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">                 <span class="sr-only">Toggle navigation</span>                      <span class="icon-bar"></span>                      <span class="icon-bar"></span>                      <span class="icon-bar"></span>              </button>              <a class="navbar-brand" href="HomePage.php"><b> Training Log Database </b></a>            </div>              <ul class="nav navbar-right top-nav">                   <li class="dropdown">                       <!-- PHP REFER LOGIN NAME-->                        <a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> M Farhan M Fazli <b class="caret"></b></a>                         <ul class="dropdown-menu">                              <li>                                  <a href="MyProfile.php"><i class="fa fa-fw fa-user"></i> Profile</a>                             </li>                             <li class="divider"></li>                            <li>                              <!-- PHP LOGOUT FUNCTION -->                              <a href="LoginPage.html"><i class="fa fa-fw fa-power-off"></i> Log Out</a>                          </li>                      </ul>                  </li>              </ul>              <!-- Sidebar Menu Items start here -->              <div class="collapse navbar-collapse navbar-ex1-collapse">                  <ul class="nav navbar-nav side-nav">                      <li>                          <a href="HomePage.php"><i class="fa fa-fw fa-dashboard"></i> Home</a>                      </li>                      <li>                          <a href="ManageAdministrator.php"><i class="fa fa-fw fa-bar-chart-o"></i> Manage Administrator</a>                      </li>                      <li>                        <!-- Add new pages here -->                          <a href="#"><i class="fa fa-fw fa-bar-chart-o"></i> Manage Staff</a>                      </li>                      <li>                          <a href="javascript:;" data-toggle="collapse" data-target="#demo"><i class="fa fa-fw fa-edit"></i> Manage Training<i class="fa fa-fw fa-caret-down"></i></a>                          <ul id="demo" class="collapse">                              <li>                                  <a href="TrainingList.php">Training Information</a>                              </li>                              <li>                                  <a href="#">TBA</a>                              </li>                                                      </ul>                      </li>                      <li>                          <a href="javascript:;" data-toggle="collapse" data-target="#demo1"><i class="glyphicon glyphicon-wrench"></i>  Tools for Administrator<i class="fa fa-fw fa-caret-down"></i></a>                          <ul id="demo1" class="collapse">                            <li><a href="#"> Add News </a></li>                            <li><a href="#"> Add Announcement </a></li>                            <li><a href="#"> Search News</a> </li>                            <li><a href="#"> Search Announcement </a></li>                            <li><a href="#"> View My Post </a></li>                          </ul>                      </li>                      <li>                          <a href="#"><i class="glyphicon glyphicon-info-sign"></i> About</a>                      </li>                      <li>                          <a href="#"><i class="glyphicon glyphicon-question-sign"></i> FAQs</a>                      </li>                                                  </div>              <!-- /.navbar-collapse -->          </nav>          <div id="page-wrapper">           <div class="container-fluid">            <div class="row col-lg-12">             <h2 class="page-header"> Update Administrator Account </h2>             <div class="row col-lg-12">              <h3> Administrator details </h3>              <div class="row col-lg-12">          <form class="form-horizontal form-group" action="adminUpdate.php?id=<?php echo $staffID?>" method="post">              <!-- <div class="form-group col-lg-12 <?php echo !empty($staffIDError)?'error':'';?>">              <label>Administrator Staff ID</label>                <input class="form-control" name="staffID" type="text" value="<?php echo !empty($staffID)?$staffID:'';?>">                  <?php if (!empty($staffIDError)): ?>                    <span class="help-inline"><?php echo $staffIDError;?></span>                   <?php endif; ?>             </div>-->              <div class="form-group col-lg-12 <?php echo !empty($adminNameError)?'error':'';?>">              <label>Administrator Name</label>                <input class="form-control" name="adminName" type="text" value="<?php echo !empty($adminName)?$adminName:'';?>">                  <?php if (!empty($adminNameError)): ?>                    <span class="help-inline"><?php echo $adminNameError;?></span>                   <?php endif; ?>            </div>              <div class="form-group col-lg-12 <?php echo !empty($emailError)?'error':'';?>">              <label>Administrator Email</label>                <input class="form-control" name="email" type="text" value="<?php echo !empty($email)?$email:'';?>">                  <?php if (!empty($emailError)): ?>                    <span class="help-inline"><?php echo $emailError;?></span>                   <?php endif; ?>            </div>            <div class="form-group col-lg-12 <?php echo !empty($ExtnError)?'error':'';?>">             <label> Extension Number </label>              <input class="form-control" name="Extn" type="text" value="<?php echo !empty($Extn)?$Extn:'';?>">               <?php if (!empty($ExtnError)): ?>                <span class="help-inline"><?php echo $ExtnError;?></span>               <?php endif; ?>             </label>            </div>            <div class="form-group col-lg-12 <?php echo !empty($SKGError)?'error':'';?>">              <label>SKG</label>                <select class="form-control" name="SKG" value="<?php echo !empty($SKG)?$SKG:'';?>">                   <option> SKG 09 </option>                   <option> SKG 18 </option>                   <option> SKG 20 </option>                   <option> SKG 16 </option>                   <option> SKG 11 </option>                   <option> SKG 13 </option>                   <option> SKG 14 </option>                   <option> SKG 12 </option>                   <option> SKG 15 </option>                   <option> SKG 10 </option>                   <option> SKG 25 </option>                  </select>                  <?php if (!empty($SKGError)): ?>                    <span class="help-inline"><?php echo $SKGError;?></span>                   <?php endif; ?>            </div>             <!-- <div class="form-group col-lg-12 <?php echo !empty($passwordError)?'error':'';?>">              <label>Password</label>                <input type="password" name="password" id="password" class="form-control" placeholder="Password" value="<?php echo !empty($password)?$password:'';?>">                  <?php if (!empty($passwordError)): ?>                    <span class="help-inline"><?php echo $passwordError;?></span>                   <?php endif; ?> -->            </div>            <div class="form-actions col-lg-12">              <button type="submit" class="btn btn-success">Update</button>              <a class="btn btn-default" href="ManageAdministrator.php">Back</a>            </div>                 </form>                </div>             </div>            </div>           </div>          </div>      </div><!--wrap-->    </body>  </html>     

Here's the Connect.php

<?php  class Database   {   private static $dbName = 'tlad' ;    private static $dbHost = 'localhost' ;   private static $dbUsername = 'root';   private static $dbUserPassword = '';      private static $cont  = null;      public function __construct() {    exit('Init function is not allowed');   }      public static function connect()   {      // One connection through whole application         if ( null == self::$cont )         {                try           {            self::$cont =  new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword);            }          catch(PDOException $e)           {            die($e->getMessage());            }         }          return self::$cont;   }      public static function disconnect()   {    self::$cont = null;   }  }  ?>

Here's my table: enter image description here

As I mentioned earlier, the read, create and delete function are working except for this update function aren't.

Please note: I've followed a tutorial on creating a CRUD datatable, while his template worked but my code aren't. Here's the tutorial's code for update template:

<?php       require 'database.php';     $id = null;   if ( !empty($_GET['id'])) {    $id = $_REQUEST['id'];   }      if ( null==$id ) {    header("Location: index.php");   }      if ( !empty($_POST)) {    // keep track validation errors    $nameError = null;    $emailError = null;    $mobileError = null;        // keep track post values    $name = $_POST['name'];    $email = $_POST['email'];    $mobile = $_POST['mobile'];        // validate input    $valid = true;    if (empty($name)) {     $nameError = 'Please enter Name';     $valid = false;    }        if (empty($email)) {     $emailError = 'Please enter Email Address';     $valid = false;    } else if ( !filter_var($email,FILTER_VALIDATE_EMAIL) ) {     $emailError = 'Please enter a valid Email Address';     $valid = false;    }        if (empty($mobile)) {     $mobileError = 'Please enter Mobile Number';     $valid = false;    }        // update data    if ($valid) {     $pdo = Database::connect();     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);     $sql = "UPDATE customers  set name = ?, email = ?, mobile =? WHERE id = ?";     $q = $pdo->prepare($sql);     $q->execute(array($name,$email,$mobile,$id));     Database::disconnect();     header("Location: index.php");    }   } else {    $pdo = Database::connect();    $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);    $sql = "SELECT * FROM customers where id = ?";    $q = $pdo->prepare($sql);    $q->execute(array($id));    $data = $q->fetch(PDO::FETCH_ASSOC);    $name = $data['name'];    $email = $data['email'];    $mobile = $data['mobile'];    Database::disconnect();   }  ?>      <!DOCTYPE html>  <html lang="en">  <head>      <meta charset="utf-8">      <link   href="css/bootstrap.min.css" rel="stylesheet">      <script src="js/bootstrap.min.js"></script>  </head>    <body>      <div class="container">               <div class="span10 offset1">          <div class="row">           <h3>Update a Customer</h3>          </div>                  <form class="form-horizontal" action="update.php?id=<?php echo $id?>" method="post">         <div class="control-group <?php echo !empty($nameError)?'error':'';?>">           <label class="control-label">Name</label>           <div class="controls">              <input name="name" type="text" value="<?php echo !empty($name)?$name:'';?>">              <?php if (!empty($nameError)): ?>               <span class="help-inline"><?php echo $nameError;?></span>              <?php endif; ?>           </div>         </div>         <div class="control-group <?php echo !empty($emailError)?'error':'';?>">           <label class="control-label">Email Address</label>           <div class="controls">              <input name="email" type="text" value="<?php echo !empty($email)?$email:'';?>">              <?php if (!empty($emailError)): ?>               <span class="help-inline"><?php echo $emailError;?></span>              <?php endif;?>           </div>         </div>         <div class="control-group <?php echo !empty($mobileError)?'error':'';?>">           <label class="control-label">Mobile Number</label>           <div class="controls">              <input name="mobile" type="text" value="<?php echo !empty($mobile)?$mobile:'';?>">              <?php if (!empty($mobileError)): ?>               <span class="help-inline"><?php echo $mobileError;?></span>              <?php endif;?>           </div>         </div>         <div class="form-actions">          <button type="submit" class="btn btn-success">Update</button>          <a class="btn" href="index.php">Back</a>        </div>       </form>      </div>            </div> <!-- /container -->    </body>  </html>
</div
        
   
   

回答リスト

3
 
vote
vote
ベストアンサー
 

<コード> execute には5つのパラメータがありますが、クエリは6です。

<事前> <コード> $sql = "UPDATE admin set staffID = ?, adminName = ?, email = ?, SKG = ?, Extn = ? WHERE staffID = ?"; $q = $pdo->prepare($sql); $q->execute(array($staffID, $adminName, $email, $SKG, $Extn, $staffID));

email 99887665

の前の $ も欠落していました。
 

Your execute has 5 parameters, but query wants 6.

$sql = "UPDATE admin  set staffID = ?, adminName = ?, email = ?, SKG = ?, Extn = ?  WHERE staffID = ?"; $q = $pdo->prepare($sql); $q->execute(array($staffID, $adminName, $email, $SKG, $Extn, $staffID)); 

Also were missing $ in front of email, SKG and Extn.

</div
 
 
     
     

関連する質問

1  Oracle SQL - 別の属性値に基づいて同じテーブルを更新する  ( Oracle sql update same table based on another attribute value ) 
Oracleには、次の値を持つ4つの属性を持つテーブルがあります。 <事前> <コード> attribute_a attribute_b attribute_c attribute_d abcd1 ...

0  他のテーブルから小計に基づいてフィールドを更新します  ( Update a field based on subtotal from another table ) 
Oracle(10)を使用しています。 次の2つのテーブルを持っています: <事前> <コード> Table1 (uniq rows): ID AMOUNT DATE Table2: ID AMOUNT1 AMOUNT2 ...AMO...

0  MSSQL Trigger更新プログラムの更新  ( Mssql trigger update on column ) 
私は2つのテーブルを持っています、そして表2に挿入または更新するトリガーを持つことができますが、それを行う方法はわかりません。 表1: <事前> <コード> CREATE TABLE [dbo].[DevicePorts]( [ID] [int] ID...

3  Query SQLite - Androidの更新  ( Update query sqlite android ) 
私のAndroidアプリでSQLiteで簡単なアップデートクエリを解読することができません。ここでクエリ、 <事前> <コード> int fav = 1; Cursor c = sqliteDB.rawQuery("UPDATE "+ MyConstants....

26  更新トリガを使用して別のテーブルを更新する方法は?  ( How to use update trigger to update another table ) 
トリガーが登録され、列の更新にトリガーを作成し、その値で別のテーブルを更新したいです。 私は1年の列を持つTable1を持っています、そして、その年の列を更新する必要がある場合は、同じ年の年の表2を更新する必要があります。 <事前> <コード> spring9...

412  MySQLの複数の更新プログラム  ( Multiple updates in mysql ) 
私はあなたが一度に複数の行を挿入できることを知っています、MySQLで一度に(1つのクエリで)複数の行を更新する方法はありますか? 編集: たとえば、次のがあります。 <事前> <コード> property DispPitch: TDispPitch read...

1  FORM値からのPHP MySQLの更新文生成  ( Php mysql update statment generation from form values ) 
私は非常に小さいデータベースの抽象レイヤを作成しています、私はフォームから取得した変数の配列を送信し、更新SQL文を生成し、最終的に実行します。 下記の2行目に何を置くのですか? 例えば <事前> <コード> $table name = "user"; $us...

1  TSQLアップデートの問題  ( Tsql update issue ) 
OK SQL Serverファンには、SQL Server 2008 R2インスタンスの内側にあるレガシーストアドプロシージャーがあり、最小のものが恐ろしいことを示すPRODデータでも継承しています。また、データやテーブル構造を変更することはできません。 ...

-1  PHPの状態でMySQLを更新する  ( Update mysql in if condition in php ) 
私は問題があります。 visual_form_builder (WordPressプラグイン)では、フィールドの値を投稿し、次のフィールド値を付けてからMySQLテーブルのレコードを更新したいと思います。 問題は、条件がない場合、 9988777663 コ...

0  他のMySQLクエリの出力(その値)を使用する必要があります。  ( I need to use the output its value of one mysql query in another ) 
1つのクエリの出力を他の値として使用するのに問題があります。そのようなことは、次のクエリを使用して1つの製品(これに成功した)の価格を取得する必要があります。 <コード> SELECT Cena FROM Proizvod WHERE ProzivodID...




© 2022 cndgn.com All Rights Reserved. Q&Aハウス 全著作権所有