Form that inserts SQL database entries that expire

I know its easily possible to insert the user entered information from a PHP form to an SQL database but is there possible PHP code to make the database entries expire after say like a month or so and have it removed or any other ways of doing this?

What I want to do is have users enter specific information into a form that grants them access to a gaming server on my community with elevated features by entering there information submitted into an SQL database, then having those entries in the database expire somehow after 1 month.

Thanks in advance!

I remember hearing about having the PHP check a specific web page for the matching code of the user when they entered that info. And if it is found they are added to the database. But then I would have to be able to make that code on the webpage expire and be removed.

in your user table of the database add the columns ‘access’ and ‘expire’… both VARCHAR(20) both with default of ‘no’

then when a user signs up for access get the users username and put it in $username then run
[php]
$todayDate = date(“Y-m-d”);
$dateOneMonthAdded = strtotime(date(“Y-m-d”, strtotime($todayDate)) . “+1 month”);
$expiredate = date(‘Y-m-d’,$dateOneMonthAdded);

$dbhost = “…”;
$dbuser = “…”;
$dbpass = “…”;
$dbname = “…”;

$dbconnection=mysql_connect($dbhost, $dbuser, $dbpass);
$db_selected=mysql_select_db($dbname, $dbconnection);
$result=mysql_query(“UPDATE users SET access = ‘yes’ AND expire = ‘$expiredate’ WHERE username = ‘$username’”);
[/php]

then on your login page add this
[php]
$todayDate = date(“Y-m-d”);
$dbhost = “…”;
$dbuser = “…”;
$dbpass = “…”;
$dbname = “…”;

$dbconnection=mysql_connect($dbhost, $dbuser, $dbpass);
$db_selected=mysql_select_db($dbname, $dbconnection);
$result=mysql_query(“SELECT * FROM users WHERE user = ‘$user’”);
$row = mysql_fetch_array($result);

$access = $row[‘access’];
$expire = $row[‘expire’];

if($access == “yes”){
if($expire <= $todayDate){
$result=mysql_query(“UPDATE users SET access = ‘no’ AND expire = ‘none’ WHERE username = ‘$username’”);
$granted = “no”;
} else {
$granted = “granted”;
}
} else {
$granted = “no”;
}
[/php]

put granted in a session variable, have the user redirected, do what you want this is just an example of how you can do it.

See anything wrong with this simple form code? If not how can I integrate that code above into it? I’m sorry but I’m a big noob with PHP.

[php]

Server Donation Page <?php $hostname = "thatsactuallyfunny.com"; $db_user = "dbuser (omitted)"; $db_password = "dbpassword (omitted)"; $database = "thatsact_sadadmins"; $db_table = "sm_admins"; $db = mysql_connect($hostname, $db_user, $db_password); mysql_select_db($database,$db); if (isset($_REQUEST['Submit'])) { $sql = "INSERT INTO $db_table(id,user_email) values ('".mysql_real_escape_string(stripslashes($_REQUEST['id']))."','".mysql_real_escape_string(stripslashes($_REQUEST['user_email']))."')"; if($result = mysql_query($sql ,$db)) { echo '

Thank you,

 your information has been entered into our database sucessfully.

Server Donation Page


Steam ID (format STEAM_0:x:xxxxxxxx, go to Steam ID Finder):

Your Email:


<?php } ?> [/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service