Hello , I have to make a code that will deny to all normal users to edit or delete contacts ,5 minutes after their adding . I've been reading a lot , but didn't found the answer... Can you help me with a lay to do this code ?
How to do something after 5 min
you should save the insertation date-time with the data you want to insert in a new field.
Before update you can get the difference between now and that time.
date_add()
Can I just insert only the minutes of the , and if 5 minutes have passed to update a row in the DB for example:
if (date("i") > $row['minutes'] )
And then just updating the row .
Fodor;10972563 wrote:Can I just insert only the minutes of the , and if 5 minutes have passed to update a row in the DB for example:
and if they post on minute 60 ? or 5 hours and 1 minute ago ...
so no, you need the full time and date.
You could even have MySQL do all of the work for you (assuming you're using MySQL, that is), e.g.:
SELECT col1, col2, ... IF(dateCol < NOW() - INTERVAL 5 MINUTE, '', '1') AS canEdit, ..
Then you'd simply do something like:
if($row['canEdit']) {
// within 5 minutes ...
} else {
// more than 5 minutes ago
}
EDIT: Furthermore, depending upon the schema, you can even have MySQL automatically add the current timestamp to each row being inserted into the table.