1

i want my users to be able to post a task once a day and if they have posted that day they cant post again till the next day but the codes i know arent working for me please guys help // initializing variables

$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");

}
  }

i have a database that has a post input and a date as current_timestamp but i want my users to be able to post once everyday only but i cant seem to get it right please help guys thanks alot

AKATUGBA
  • 24
  • 5
  • As I said in the answer linked, create a unique constraint in the database to prevent duplicate entries. Make sure that your column has data type DATE – Dharman Mar 31 '21 at 12:15
  • yes the data type of the database table named date is DATE but it doesnt seem to work, i feel my codes arent correct because the date is adding from the database as current time stamp, i really dont know to solve this please help – AKATUGBA Apr 01 '21 at 07:25

0 Answers0