lundi 29 août 2016

Database not being updated because of session, update query gives no error.

I'm currently working on a php user admin system for work. I'm able to create new users. I'm able to update the user account that I'm logged into--first name, last name, email, and password. I created a page that generates users information in a table. It shows user id, username, first name, last name, email address with an delete and edit link. The delete script works. The edit link goes to a form so I can update user info. The problem I'm having is: when I update the users information it's not updating it in the database. I can only update users information if I'm logged as that user. I'm using sessions, and I think it has something to do with my issues. Here's the code. This script is run after I press submit to update user information. Any help would be appreciated. Thanks.

<?php


require("connect.php");

if(empty($_SESSION['user']))
{

    header("Location: ../hound/login.php");


    die("Redirecting to ../hound/login.php");
}


 $array_value = array(
        ':email' => $_POST['email'],
        ':first_name' => $_POST['first_name'],
        ':last_name' => $_POST['last_name'],
        ':id' => $_POST['id']
  );



     $query = "UPDATE users 
        SET 
        email = :email,
        first_name = :first_name, 
        last_name = :last_name

        WHERE
          id = :id
    ";


       try
    {

        $stmt = $db->prepare($query);
        $result = $stmt->execute($array_value);
    }
    catch(PDOException $ex)
    {

        die("Failed to run query: " . $ex->getMessage());
    }



    header("Location: users.php");


    die("Redirecting to users.php");

   ?>




Aucun commentaire:

Enregistrer un commentaire