When I login same script works for first user but for other user, it gives error in connection.
More over i want to fetch data from database

Main File is

<?php

    include_once("../init.php");
    validation_check($_SESSION['SID'],MEM_HOME_ADMIN);
    $msg='';

    $dir ='../'.USER_PIC;
    $sId = $_SESSION['SID'];

    $query = mysql_query("select * from user WHERE user = ".$sId) or die('Error in connection');
    while ($rows = mysql_fetch_array($query));


?>

I want to fetch join_date, phone, sponsor, address etc from user table
Login file is

<?php


    if(isset($_POST['click']))
    {
        $user = trim($_POST['user']);    
        $pass = trim($_POST['pass']);    
        if(($user =='' )|| ($pass=='')){
            $msg ='Please enter username & password';    
        }else{
            $npass = ($pass);
            $fstu = mysql_query("select * from user where user ='$user'");
            if(mysql_num_rows($fstu)==0) {
                $msg ='Invalid UserName';    
            } else {
                $res = mysql_fetch_array($fstu);
                if($res['pass']==$npass) {


                        $_SESSION['USE_USER']        = $res['user'];
                        $_SESSION['SID']            = $res['id'];

                        header('location: main.php');
                } else {
                    $msg ='Invalid Password';    
                }

            }        
        }
    }
?>

Function file is

function logout($destinationPath)
    {
        if(count($_SESSION))
        {
            foreach($_SESSION AS $key=>$value)
            {
                session_unset($_SESSION[$key]);
            }
            session_destroy();
        }
        echo "<script language='javaScript' type='text/javascript'>
                window.location.href='".$destinationPath."';
            </script>";
    }
    function validation_check($checkingVariable, $destinationPath)
    {
        if($checkingVariable == '')
        {
            echo "<script language='javaScript' type='text/javascript'>
                window.location.href='".$destinationPath."';
            </script>";
        }
    }



databse  connection file is



//USING PCONNECT OR NOT :: WRITE 'true' IF YOU ARE USING MYSQL_PCONNET OTHERWISE WRITE 'false'.
    define("USE_PCONNECT", false);

    ####### LOCAL CONFIGARATION  #######
    if($_SERVER['HTTP_HOST']=='localhost') {
        define("SERVER","localhost");
        define("USER","root");
        define("PASSWORD","");
        define("DB","lightinglife");



  database function file



 <?PHP
    function Db_Connect()
    {
        global $link;
        if (USE_PCONNECT == true)
        {
          $link = mysql_pconnect(SERVER, USER, PASSWORD) or die("Could Connect To The MySql Server".mysql_error());
        }
        else
        {
          $link = mysql_connect(SERVER, USER, PASSWORD) or die("Could Connect To The MySql Server".mysql_error());
        }
        if ($link)
        {
            mysql_select_db(DB) or die("Could Connect To The MySql Database".mysql_error());
        }
        return $link;
    }
    function Db_Close()
    {
        global $link;
        return mysql_close($link);
    }

?>




I am fetching  by    

<tr> <td>Father Name:</td> <td><?=$fstu['fname']?></td> 

this is not relevant to your question but you are using deprecated stuff here. either use mysqli or pdo

Replace line 10 with this:

$query = mysql_query("select * from user WHERE user = ".$sId) or die(mysql_error());

and tell us what the error is. My guess is that $sId is not set.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.