我尝试过Google并在网上搜索所有内容。我最终想在表INSERT
中运行一个IF
查询,该表为空,ELSE
运行一个UPDATE
查询。
我需要检查表-UserTakingModule
,字段-checkPoint
对于当前登录的用户是否为空,然后运行插入查询:
$idUsers = $_SESSION['id'];
$ModuleID = 5;
$checkPoint = 1;
// Preparing and binding my SQL query which inserts a checkpoint number into the table
$stmt = $conn->prepare ("INSERT INTO `userTakingModule` (`userTakingModuleID`, `idUsers`, `ModuleID`, `checkPoint`) VALUES (NULL, ?, ?, ?)");
$stmt->bind_param("iii", $idUsers, $ModuleID, $checkPoint);
$stmt->execute();
但是,如果checkPoint
中已经保存了一个整数,则只需对当前登录的用户运行UPDATE查询:
// Else need an update query to run for user that's currently logged in
$stmt = $conn->prepare ("UPDATE `userTakingModule` SET `checkPoint` = ? WHERE `userTakingModule`.`userTakingModuleID` = ?");
$stmt->bind_param("ii", $idUsers, $ModuleID, $checkPoint);
$stmt->execute();
注意 在UPDATE
查询中占位符的位置我不确定如何在checkPoint
中获取当前项。任何帮助都会减轻女孩的压力!