简体   繁体   English

数据库未使用PDO语句更新?

[英]Database not updating with PDO statement?

Is there something wrong with the syntax of the statement? 语句的语法有问题吗? I've been messing around with inserting different variables into the code and it still wont update in phpmyadmin. 我一直在把不同的变量插入代码中,但在phpmyadmin中它仍然不会更新。 Pretty new with this language so please bear with me. 这种语言很新,所以请忍受我。

Pretty sure the line giving me the issue is: 可以肯定的是,出现问题的行是:

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

I just don't know what the issue is... 我只是不知道问题是什么...

<?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';
              }
         }
         ?>

_Try something along these lines: _尝试以下方法:

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

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

And as tadman said,... NEVER trust anything from a browser. 正如塔德曼所说,...永远不要相信浏览器的任何东西。 (includes $_REQUEST, $_GET, $_POST, $_COOKIE, etc.) (包括$ _REQUEST,$ _ GET,$ _ POST,$ _ COOKIE等)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM