【发布时间】:2020-09-30 04:47:52
【问题描述】:
我正在使用下面的代码从另一个表中获取用户 ID 并在该表中创建一个新记录。在同一行中有一个名为 action 的字段,我想在该字段中为同一记录插入“登录”或“注销”。
我的问题是我不确定如何在没有数据库创建新空行的情况下将其与下面的代码合并
try{
// check for user ID in sessions table and apply to new session_log record
$sql = "INSERT INTO session_logs (USER_ID, first, last, email) SELECT USER_ID, first, last, email FROM sessions WHERE email=:email";
$stmt = $pdo->prepare($sql);
// Bind parameters to statement
$stmt->bindParam(':email', $_REQUEST['email']);
// Execute the prepared statement
$stmt->execute();
} catch(PDOException $e){
die("ERROR: Could not able to execute $sql. " . $e->getMessage());
}
【问题讨论】: