普通网友 2018-01-12 00:26
浏览 45

PDO错误42000

i had an error when i run my code and i don't understand this error

error: Fatal error: Uncaught PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE UserID = 'ahmed' SET Username = 'adasda@dmail.ck',Email = 'ahmed',FullName' at line 1 in C:\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();
}
?>

ommers\first_project\admin\members.php on line 110

</div>
  • 写回答

1条回答 默认 最新

  • dongpu2727 2018-01-12 00:32
    关注

    Your update query is incorrect, you need to use the following:

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

    And change the rest of the code accordingly.

    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端