Forum Moderators: coopster
function login()
{
global $db, $smarty, $id;
$sql = "select count(*) from users where nick='".$_POST['nick']."' and psw = '".$_POST['psw']."'";
if ($db->getOne($sql))
{
$id = $db->getOne("select id from users where nick='".$_POST['nick']."'");
....
}
else
{
....
then i need to use the $id, and it's value got from $db->getOne("select id from users where nick='".$_POST['nick']."'") in another *.php
how can i do it?
greatfull for any help.
Thanks!
You can use sessions [us3.php.net]. Try the following:
[url=http://us3.php.net/manual/en/function.session-start.php]session_start[/url]();
function login()
{
global $db, $smarty, $id;
$sql = "select count(*) from users where nick='".[url=http://us3.php.net/manual/en/function.mysql-real-escape-string.php]mysql_real_escape_string[/url]($_POST['nick'])."' and psw = '".mysql_real_escape_string($_POST['psw'])."'";
if ($db->getOne($sql))
{
$_SESSION["id"] = $db->getOne("select id from users where nick='".mysql_real_escape_string($_POST['nick'])."'");
....
}
Now when you want to use the id again, initialize the session(session_start();), and get the info ($_SESSION["id"])...Good luck ;)
P.S. I added some extra security on your query. Read up on mysql_real_escape_string; it's important!
[edited by: eelixduppy at 12:35 am (utc) on June 21, 2006]
mysql_query($query) or [url=http://us2.php.net/manual/en/function.die.php]die[/url]([url=http://us2.php.net/mysql_error]mysql_error[/url]());
I also suggest encrypting the password. Whether you use mysql's PASSWORD function, or md5(prefered method), it should be encrytped. More here [webmasterworld.com]
[edited by: eelixduppy at 12:41 am (utc) on June 21, 2006]