[Solved] Retrieving user ID
Posted: Sun Aug 07, 2005 4:25 am
I got the following functions and through one of them I need to get the user ID so I can retrieve information for the user's area.
Basically, what I need is to query the MySQL database and get the user ID, I'm currently using sessions for logging in and out. I don't know where to put this code and what to put it as...
feyd |
Code: Select all
function get_area() {
$conn = db_connect();
if (!$conn)
return false;
$result = mysql_query("select province from user
where id= '$userid'");
// added a $ before result here
if (!$result)
return false;
if (mysql_num_rows($result)>0)
return true;
else
return false;
// here's a line to extract the row from the db
$array = mysql_fetch_assoc($result);
// store the province in $province
return $array['province'];
}Code: Select all
function login($user, $pass) {
$conn = db_connect();
if (!$conn)
return false;
$result = mysql_query("select * from user
where user = '$user'
and pass = MD5('$pass')");
if (!result)
return false;
if (mysql_num_rows($result)>0)
return true;
else
return false;
}
function check_valid_user() {
global $HTTP_SESSION_VARS;
if (isset($HTTP_SESSION_VARS['valid_user'])) {
echo '<div class="error">Iniciado sesión como <strong>'.$HTTP_SESSION_VARS['valid_user'].'</strong> (<a href="user.php?a=insert">Añadir datos</a> | <a href="user.php?a=view">Mostrar Datos</a> | <a href="logout.php">Desconexión</a>).</div>';
}
else {
echo '<div class="error">Su nombre de usuario o contraseña es incorecto!</div>';
include('includes/templates/login.html');
include('includes/templates/footer.html');
exit;
}
}feyd |
Code: Select all
tags make it far easier to read larger code blocks, don't you think?[/color]