首页 > 解决方案 > 使用日期每天发布一次任务

问题描述

我希望我的用户能够每天发布一次任务,如果他们当天发布了他们不能再次发布到第二天但是我知道的代码对我不起作用请大家帮忙//初始化变量

$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 但我希望我的用户每天只能发布一次但我似乎无法正确请帮助大家非常感谢

标签: phphtmldatabasemysqli

解决方案


推荐阅读