Jump to content

PHP Form Auto-Empty Script


vigiw

Recommended Posts

Hello,

I have a working PHP form that sends data to my MySQL database.  It is used for a weather alert system.  One of the fields in the form & database is an expiration field.  It shows the user when the alert will expire.  Is there a way to auto-delete just the data sent with that form when it is supposed to expire?  I have many weather alerts and I would like them to be emptied from the database when it is needed.

Please help, this is a much needed feature.  All help appreciated :)

Thank you so much!
Link to comment
https://forums.phpfreaks.com/topic/21788-php-form-auto-empty-script/
Share on other sites

Sounds like a case for re-thinking db design. You shouldn't be creating and dropping tables from an application. I'm surprised your DBA allows it.

Can you explain your whole scenario, from creating the alerts (and why in different tables) to deleting them?
No, I don't want to delete tables.  I was just verifying that it only empties the data that I want it to, and not deleting.

I have a weather forecast system, it officially launched to the public last night.  I have different forecast areas and different alert types and so they are in their own tables of one database.  It is already working, the hard part is over.  I just want the old data to be removed.

I have another question:

What format does the expiretime have to be in?

Date, Time, maybe, I don't know the exact format to make the database understand.

Thanks.
Ok Thanks..


Is there a way to make this script automatic?  Maybe cron jobs?

I honestly do not know what a cron job is and have never used one so I would not know what to do.

It seems very tedious running this every so often since there will be quite the amount of alerts to empty when needed.
[quote]Is there a way to make this script automatic?[/quote]

[quote author=Barand link=topic=109197.msg440039#msg440039 date=1159038196]
I'd set it up so that when you add an alert to one of your tables, also call the query to delete any expired ones from that table.
[/quote]
You said you have working form that writes the alerts to your database.

So if you processing script is inserting a record into, say, alerts2 table, then also

mysql_query ("DELETE FROM alerts2 WHERE expiretime < NOW()");

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.