数据库没有用PDO语句更新?

时间:2017-10-21 18:30:17

标签: php mysql pdo

语句的语法有问题吗?我一直在搞乱在代码中插入不同的变量,它仍然不会在phpmyadmin中更新。这个语言很新,所以请耐心等待。

非常肯定这条线给我的问题是:

$pdoQuery ="UPDATE `Lab4` SET `ActiveUser`=".$Yes." WHERE UserName=".$Email."";

我只是不知道问题是什么......

<?php
   //connect to the database
   session_start(); //this must be the very first line on the php page, to register this page to use session variables
      $_SESSION['timeout'] = time();

   //if this is a page that requires login always perform this session verification
   //require_once "inc/sessionVerify.php"; 

     require_once "dbconnect.php";
     require_once "inc/util2.php";
     require_once "mail/mail.class.php";

      include "header.php";

   // $EmailCode = $_GET["Code"];
     if (isset($_SESSION['Code'])){
     echo $_SESSION['Code'];
     echo $_SESSION['Email'];
     }
     ?>


      <?php 
        if (isset($_POST['Submit'])){

                 try {
                  $pdoConnect = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);

              }
              catch (PDOException $exc) {
                  echo $exc->getMessage();
                  exit();
              }
              //$NotAnActiveUserYet = "No";            
             // mysql query to insert data
            $Email = $_SESSION['Email'];
             $Yes = "Yes";  



              $pdoQuery ="UPDATE `Lab4` SET `ActiveUser`=".$Yes." WHERE UserName=".$Email."";
              $pdoResult = $pdoConnect->prepare($pdoQuery);
              $pdoResult->execute(); 
              if ($pdoResult) {
                  echo 'Data Inserted';
              } else {
                  echo 'Data Not Inserted';
              }
         }
         ?>

1 个答案:

答案 0 :(得分:1)

_尝试以下几点:

$params = array(
    'ActiveUser' => $Yes,
    'UserName' => $Email,
);

$pdoQuery ='UPDATE `Lab4` SET `ActiveUser`=:ActiveUser WHERE `UserName`=:UserName';
$pdoResult = $pdoConnect->prepare($pdoQuery);
$pdoResult->execute($params);

正如塔德曼所说,......从不信任浏览器中的任何东西。 (包括$ _REQUEST,$ _GET,$ _POST,$ _COOKIE等)