php queston

houssam_ballout

New Member
hello all
well on php,I am working to create and develop a login and resigtration system (not a complicated one), i want some method to login, when some one enter his username and password, how do I search the databse for his records?
I know some method, but I want a more efficient one
thanks
 
what I use is:
PHP:
//prepare query for database insertion
function prep($value)
{
    $value = trim(stripslashes($value));

    if (function_exists('mysql_real_escape_string'))
    {
        return mysql_real_escape_string($value);
    }
    else
    {
        return mysql_escape_string($value);
    }
}

$user='enteresuser';
$pass='enteredpass';
$user=prep($user);
$pass=prep($pass)
$real=mysql_fetch_array(mysql_query("SELECT * FROM `databasename` WHERE user='$user' LIMIT 0,1"))
//then the values returned are in the form of array, for example $real['username']; would refer to the table username from the database

If you want more explaining please ask, i'm not that great at commenting, also that may need debugging, i just wrote that without checking
 
You have to go to the database and that means a select statement but you only need to do that until the user logs out or their session expires from inactivity. Look at PHPs session settings or using cookies.
 
Back
Top