Im working on a login script but am having trouble with lastInsertId();
Here's the code;
<?php
session_start();
db = new PDO("mysql:host=hostname;dbname=database name", user, password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
try {
$db->beginTransaction();
$db->query("INSERT INTO `subscribers`(`subscribers`.`first_name`, `subscribers`.`last_name`) VALUES ('Jane', 'Doe')");
$db->query("UPDATE `subscribers` SET `first_name`='John' WHERE `ID` =".$db->lastInsertId());
$db->commit();
$LastID = $db->lastInsertId();
$_SESSION['user_id'] = $LastID;
} catch (PDOException $e) {
$db->rollBack();
die($e->getMessage());
}
?>
My problem is that the UPDATE query performs properly (based off of WHERE ID
=".$db->lastInsertId());) but when I try to use the function for setting the $_SESSION as seen in the code all I get back is 0.
If anyone wouldn't mind showing me what's askew I'd be most appreciative and I thank you in advance.