php - 使用日期每天发布一次任务
问题描述
我希望我的用户能够每天发布一次任务,如果他们当天发布了他们不能再次发布到第二天但是我知道的代码对我不起作用请大家帮忙//初始化变量
$post = "";
$date = "";
// POST
if (isset($_POST['pst'])) {
// receive all input values from the form
$post= mysqli_real_escape_string($db, $_POST['post']);
$date= mysqli_real_escape_string($db, $_POST['date']);
if (empty($post)) { array_push($errors, "You Must Select A Plan First"); }
else {
array_push($success, "Plan Request Recieved!!, You Will Recieve A Message Shortly, Always visit Your <u>Inbox");
}
//Fetch user ID
$xyttq = $_SESSION['email'];
$sql = "SELECT id FROM users where email = '$xyttq'";
$result = mysqli_query($db, $sql);
// fetch the resulting rows as an array
$pizaq = mysqli_fetch_all($result, MYSQLI_ASSOC);
foreach($pizaq as $pizq){
// echo ($pizq['id']);
$uidbq = ($pizq['id']);
}
// free the $result from memory (good practise)
mysqli_free_result($result);
// first check the database to make sure
// a user does not already exist with the same username and/or email
$user_check_query = "SELECT * FROM posts WHERE date='$date' LIMIT 1";
$result = mysqli_query($db, $user_check_query);
$user = mysqli_fetch_assoc($result);
if ($user) { // if user exists
if ($user['date'] === $date) {
array_push($errors, "Request already exists");
}
}
// Finally INSERT user if there are no errors in the form
if (count($errors) == 0) {
$query = "INSERT INTO posts (userid, post)
VALUES('$uidbq', '$post')";
$results = mysqli_query($db, $query);
if (mysqli_affected_rows($db) == 1) {
header('location: Notification');
}
}else {
array_push($errors, "Request Already Exist");
}
}
我有一个数据库,其中有一个帖子输入和一个日期作为 current_timestamp 但我希望我的用户每天只能发布一次但我似乎无法正确请帮助大家非常感谢
解决方案
推荐阅读
- docker - Flask Docker - 2 容器通信 - ConnectionError:HTTPConnectionPool:url 超出最大重试次数:
- list - (l+v) :: ...(list + integer :: (cons operand) ..) 在 SML 中是什么意思?
- pdf - 使用从 Web 表单中检索到的信息生成 PDF
- java - java.util.List 不能用 List.of 分配类
- android - 如何将日期时间从 MST 转换为 EST?
- linux - 如何在 Linux 中将流量从 VXLAN 转发到 TUN 接口
- wordpress - 禁用移动 html 缩放 (wordpress)
- reactjs - Django-React App 静态/媒体服务方法
- azure - 代码覆盖率 - Azure Pipelines SonarQube
- spring-boot - cmsjdbc.internals.TDS.Channel :已协商 TLSv1。请更新服务器和客户端以至少使用 TLSv1.2。在春季启动