PDO错误42000

时间:2018-01-12 00:26:45

标签: php mysql

我运行代码时出错,我不明白这个错误

错误: 致命错误:未捕获PDOException:SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;查看与您的MySQL服务器版本对应的手册,以便在'WHERE UserID ='ahmed'附近使用正确的语法'SET Username ='adasda @ dmail.ck',Email ='ahmed',FullName'在C:1的第1行wamp64 \ WWW \ eC的

<?php
/*
==============================================================
= Manage Member do
= you can Add | Edit | Delete Members from here
==============================================================
*/

session_start();
$pageTitle = 'Members';

if(isset($_SESSION['Username'])){
  include 'init.php';



  $do = isset($_GET['do']) ? $_GET['do'] : 'Manage';
  // $do= '';
  //
  // if(isset($_GET['do'])){
  //
  //   $do = $_GET['do'];
  // }else {
  //   $do = 'Manage';
  // }
  // start Manage do
  if ($do == 'Manage') {
    echo 'welcom in manage do';

    //Manage page

  }elseif ($do == 'Edit') {  //edit page

    // check If the GET Request is Numeric && Get the Integer value of it

    $userid = isset($_GET['userid']) &&  ($_GET['userid']) ? intval($_GET['userid']) : 0;
    // Select the row of user from the table

    // select All data Depend on this Id

    $stmt = $con->prepare("SELECT * FROM users WHERE UserID = ? LIMIT 1");
    // extract Query
    $stmt->execute(array($userid));
    // Fetch the data
    $row = $stmt->fetch();
    // the row count
    $count = $stmt->rowCount(); // to count the row in the table

    if ($stmt->rowCount() > 0) {
      ?>
      <h1 class="text-center">Edit Member</h1>
      <div class="container">
        <form class="form-horizontal" action="?do=Update" method="POST">
          <input type="hidden" name='userid' value="<?php echo $userid ?>"/>
          <div class="form-group form-group-lg">
            <label class="col-sm-2 control-lable">Username</label>
            <div class="col-sm-10">
              <input type="text" name="username" class="form-control" value="<?php echo $row['Username'] ?>" autocomplete="off"/>
            </div>
          </div>

          <div class="form-group form-group-lg">
            <label class="col-sm-2 control-lable">Password</label>
            <div class="col-sm-10">
              <input type="hidden" name="oldpassword"/>
              <input type="password" name="newpassword" class="form-control" autocomplete="new-password"/>
            </div>
          </div>

          <div class="form-group form-group-lg">
            <label class="col-sm-2 control-lable">E-mail</label>
            <div class="col-sm-10">
              <input type="email" name="email" class="form-control" value="<?php echo$row['Email'] ?>" autocomplete="off"/>
            </div>
          </div>

          <div class="form-group form-group-lg">
            <label class="col-sm-2 control-lable">Full-Name</label>
            <div class="col-sm-10">
              <input type="text" name="full" class="form-control" value="<?php echo$row['FullName'] ?>" autocomplete="off" />
            </div>
          </div>

          <div class="form-group form-group-lg">
            <div class="col-sm-offset-2 col-sm-10">
              <input type="submit" value="save" class="btn btn-primary btn-lg" />
            </div>
          </div>
        </form>
      </div>
      <?php
    }else {
      echo "you are not welcom in this page ";

    }
  }
  // update page
  elseif ($do == 'Update') {
    echo "<h1 class='text-center'> welcom in the update page </h1>";
    if ($_SERVER['REQUEST_METHOD'] == 'POST'){
      # get the variable from the form
      $id   = $_POST['userid'];
      $user = $_POST['username'];
      $email= $_POST['email'];
      $name = $_POST['full'];

//echo  $id . $user . $pass . $name;

  $stmt = $con->prepare('UPDATE users  WHERE UserID = ? SET Username = ?,Email = ?,FullName = ?,');
  $stmt->execute(array($user,$email,$name,$id));
  echo $stmt->rowCount() . "Record Updated";


    }else {
      echo "you cant brows this page directly";
    }
  }

  include $tpl . 'footer.php';
}else {
  header('location: index.php');
  exit();
}
?>

第110行的

ommers \ first_project \ admin \ members.php

1 个答案:

答案 0 :(得分:1)

您的更新查询不正确,您需要使用以下内容:

  $stmt = $con->prepare('UPDATE users  SET Username = ?,Email = ?,FullName = ? Where UserId =?');

并相应地更改其余代码。