A logic in php

Asked

Viewed 23 times

1

I am creating a system and I want to make sure that my user can only make five posts in the database, that is, on the site. What logic would I use to make this kind of permission? Grateful.

  • Count how many records there are and, if there are 5 yet, allow registration; otherwise, do not allow.

  • Thank you Anderson. But how would I do that? It’s that I’m a layman. I do an if by taking the value that’s in the bank? Is that I don’t know how to do this query

  • It depends a lot on your application. How is the table in the database structured? How do you identify which user is accessing the application?

  • I have a table called posts and in it has a field where I send the user id

  • Edit the question and add these details. Table structure, including column configuration, and how you are managing the user with PHP, whether you are storing in session, what code, etc.

  • Okay, just a moment

Show 1 more comment

1 answer

0


Make a select before opening the posting field to check how many posts it has already made.

If you want q be 5 posts per day, make a date field in the database, to count how many posts were made on that same date.

A simple select would already solve.

Something more or less like this:

SELECT count(id_usuario) as contador FROM suatabela WHERE data = datadehoje

then an if with the result

if (contador >= 5) { echo 'ja atingiu o limite'; } else { include('formdepostagem.php'); }

I believe that is the logic you seek. If not, try to give more details.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.