<?php
if( !isset($_SESSION) ) { session_start(); }
$database_db="cat";
$user_db="root";
$password_db="root";
$host_db="localhost";
// connect to database
mysql_connect($host_db,$user_db,$password_db) or die ("couldnot connect: ".mysql_error());
mysql_select_db($database_db, $link) or exit('Error Selecting database: '.mysql_error()); ;
// escape user input for database protection
$userid = mysql_real_escape_string($_POST["userid"]);
$password = mysql_real_escape_string($_POST["password"]);
// get user count from database, as that is all we need
$user = "SELECT count, lastlogin FROM usertab WHERE userid='$userid' AND password='$password'";
$userres = mysql_query($user);
// fetch the single user row we had selected
$row = mysql_fetch_row($userres);
// check if the user exists first
if(mysql_num_rows($userres) != 0) {
// ensure that all used account is deleted every 2 days
if($row[0] = 2) {
echo "Error - You have been used for 2 days hence deleted";
} elseif ((time() - strtotime($row[1])) > (2 * 24 * 60 * 60)) {
echo "Error - You have not logged in within two days";
// close the account (delete it for example)
mysql_query("DELETE FROM usertab WHERE userid = '$userid'");
} else {
//update their last login
mysql_query("UPDATE usertab SET lastlogin = NOW() WHERE userid = '$userid'");
//successful login, increment count by one
mysql_query("UPDATE usertab SET count = count + 1 WHERE userid = '$userid'");
//redirect them to the page
header("Location: insert1.php");
}
} else {
//if their username and password returned nothing
echo "Error - Your account does not seem to exist.";
}
?>
2 replies to this topic
#1
Posted 12 March 2011 - 01:07 PM
Good day everyone. pls I want to modify this Mr.Alexander's code to suit my objective. My intention was to delete all the used username and password from database every 2 days while leaving the unused undeleted. Please how do i proceed thank u
|
|
|
#2
Posted 12 March 2011 - 02:37 PM
You would need to set up a cron job every two days, do you have access to those on your hosting?
There are other possibilities if you do not.
There are other possibilities if you do not.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.
#3
Posted 12 March 2011 - 08:13 PM
no i dont have
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users


Sign In
Create Account


Back to top









