0

Cannot update data even thought the query seems fine.

Using PDO and Prepared Statment together in the code the header location is working and redirecting me but the data is not flashing in phpmyadmin, so assuming that there is some problem with the query.

Is the way of execution wrong or there is problem in the query

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();
?>
dhruv
  • 103
  • 2
  • 12

0 Answers0