更新期间具有预准备语句的PDO

时间:2019-04-30 06:31:24

标签: mysql pdo prepared-statement

即使查询看起来还不错,也无法更新数据。

在代码中同时使用PDO和Prepared Statment,标头位置可以正常工作并重定向我,但是phpmyadmin中的数据没有闪烁,因此假设查询存在问题。

执行方式错误还是查询有问题

Employee.php

    <?php

  ini_set('display_errors', 1);
 ini_set('display_startup_errors', 1);
 error_reporting(E_ALL);


class employees{
function __construct(){
        try {
                $this->con= new PDO("mysql:host=o7;dbname=dhruv_thakkar", 'dhruv_thakkar', 'd70');
                $this->con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
                }

        catch(PDOException $e)
                {
                echo "Connection failed: " . $e->getMessage();
                }
      }



 function update_employee($eid,$name,$email,$password,$birth_date,$gender,$postcode,$phno,$street_address,$country,$state,$city){
         $d1 = date('Y-m-d',(strtotime($birth_date)));

         /*image shit  */
         $target_dir = "uploads/";
         $target_file = $target_dir . basename($_FILES["imageUpload"]["name"]);
         $uploadOk = 1;
         $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);

         if (move_uploaded_file($_FILES["imageUpload"]["tmp_name"], $target_file)) {
         }
         $image=basename($_FILES["imageUpload"]["name"],".jpg");

            if(!empty($image))
            {
              $sql= $this->con->prepare( "UPDATE `employees` SET  name=':name',email=':email',password=':password',street_address=':street_address',
             postcode=':postcode',phone_number=':phno',birth_date=':d1',
             city=':city',state=':gender',country=':country',gender=':gender',profile_pic=':image' WHERE  emp_id=':eid'");
            }
            else {
              $sql= $this->con->prepare( "UPDATE `employees` SET  name=':name',email=':email',password=':password',street_address=':street_address',
             postcode=':postcode',phone_number=':phno',birth_date=':d1',
             city=':city',state=':gender',country=':country',gender=':gender' WHERE  emp_id=':eid'");                
            }
            $sql->bindParam(':name', $name);
            $sql->bindParam(':email', $email);
            $sql->bindParam(':gender', $gender);
            $sql->bindParam(':password', $password);
            $sql->bindParam(':street_address', $street_address);
            $sql->bindParam(':postcode', $postcode);
            $sql->bindParam(':phno', $phno);
            $sql->bindParam(':image', $image);
            $sql->bindParam(':d1', $d1);
            $sql->bindParam(':country', $country);
            $sql->bindParam(':state', $state);
            $sql->bindParam(':city', $city);
            $sql->bindParam(':eid', $eid);

          $sql->execute();
         header('location:admin.php');

     $this->con= null;
 }


}
$obj= new employees();
?>

0 个答案:

没有答案
相关问题