-1

I have a function that creates a cookie and updates a database with the cookies data accordingly but I can't seem to get the db to update from within the function. is currently unable to handle this request.

You can take for granted that the correct data is being fed into the function including $db. I can get the page to load once I comment out the two $stmt lines that prepare and execute the insert into the $db.

$db lives in a file call db.php which I require before calling the function. I've tested $db on other in page queries and it seems to work no problem.

function updatecookieDB($db, $email)
{
    $Selector = md5($email);
    $token = bin2hex(random_bytes(20));
    $salt = bin2hex(random_bytes(20));
    $cookiedata = $Selector.$token;
    $Hash = md5($token.$salt);
    setcookie('RememberMe',$cookiedata,time()+(3600*24*15),"/")
    $query = " INSERT INTO RememberMe(email,Selector,Hash,Salt) VALUES (:email,:Selector,:Hash,:Salt) ";
    $query_params = array ( ':email' => $email ,':Selector' => $Selector , ':Hash' => $Hash, ':Salt' => $salt );

    try
    {
    $stmt = $db->prepare($query); 
    $stmt->execute($query_params);
    {
    catch(PDOException $ex) { die("Failed to run query: " . $ex->getMessage()); }


}

Could it be because I'm not returning anything?

denski
  • 1,768
  • 4
  • 17
  • 35

1 Answers1

-2

I changed it to the following and it worked correctly:

    $stmt = $db->prepare($query)->execute($query_params); 
denski
  • 1,768
  • 4
  • 17
  • 35