1

I'm trying to make a account system using php and SQL. The problem is that my knowledge is limited.

Here is what my sql db looks like right now: https://i.stack.imgur.com/eqQ3G.png

What I do when someone registers them is using my API:

if ($Action == "Register"){
    $usr = mysql_escape_string($_GET['usr']);
    $pas = mysql_escape_string($_GET['pas']);
    $hwid = mysql_escape_string($_GET['hwid']);
    $code = mysql_escape_string($_GET['code']);
    $con = mysql_connect($host,$username,$password);
    if (!$con) {
        die('Could not connect: ' . mysql_error());
    }
    mysql_select_db($db_name, $con);
    mysql_query("UPDATE $table SET username = '$usr', password = '$pas', hwid = '$hwid'
    WHERE code = '$code' AND username = '-' AND password = '-' 
    AND hwid = '-' AND time = '-'");
    mysql_close($con);

What I'd like to know is how I can make sure a certain time is over and delete the entire row? For an example: They register and get a week of access, when the week is over, the account gets deleted.

Thank you guys so much for any help.

Thorsten Kettner
  • 89,309
  • 7
  • 49
  • 73
  • Read about crom job http://stackoverflow.com/questions/18737407/how-to-create-cron-job-using-php – ashkufaraz Oct 13 '16 at 09:32
  • Possible duplicate of [How to delete mysql row after time passes?](http://stackoverflow.com/questions/9865393/how-to-delete-mysql-row-after-time-passes) – S.I. Oct 13 '16 at 09:32
  • 3
    You usually do _not_ want to delete that record, but mere deactivate it. That is typically done by comparing the date of registration with the current date. That allows flexibility, for example upgrading, exceptions, change of terms, ... – arkascha Oct 13 '16 at 09:32
  • 1
    As above plus have a look at using PDO or mysqli as mysql is not the suggested method due to the risk of injection attacks. – Blinkydamo Oct 13 '16 at 09:33
  • You can use the MySQL Event Scheduler to run SQL queries periodically. – Barmar Oct 13 '16 at 09:40

1 Answers1

2

If you want to delete user automatic read about cron job http://www.thesitewizard.com/general/set-cron-job.shtml.

Else you can check user's registration time in index.php, and delete user MySQlL Query

DELET FROM USER_TABLE WHERE time < NOW() - INTERVAL 1 WEEK
Kushan
  • 10,657
  • 4
  • 37
  • 41