Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
sorry for my english knowledge.
am a student && biginer to php mysql.
while login as a user it accepting any values out of the table(mca) in my database which are allready created users. using php session
please solve this problem
thanks...

What I have tried:

HTML
#1connect.php

    <?php
mysql_connect('localhost:3306','root','') or die(mysql_error());
mysql_select_db('repository') or die(mysql_error());

?>
#2login.php

<?php
session_start();
if(isset($_POST['submit']))
{
    $name=$_POST['fname'];
    $password=$_POST['password'];
  // $dept=$_POST['department'];
    include 'connectdb.php';
    $rs='SELECT * FROM mca WHERE fname=fname and password=password';
    $res= mysql_query($rs) or trigger_error(mysql_error().$rs);
    if(mysql_num_rows($res))
    {   
        
        $_SESSION['name']=$name;
        
        
        
        $row=  mysql_fetch_array($res);
        if($row['usertype']==0)
        {
        header('location:adminaction.php');
          }
          
 else {
        echo 'Sorry Your Username or Department is  Invalid';
        header('location:login.php');
        echo "<script> alert('You are entered invalid Username and Department') </script>";
 }
    
}
}

?>
<?php
include 'header.php';
?>
<div id="intel">
    <ul >
                    <li id="z"><a href="bca.php">HOME </a>
                         </li>
                     <li id="z"><a href="stats.php"> NOTICE</a></li>
                     <li id="z"><a href="uregistration.php">NEW REGISTER</a></li>
            </ul> 
</div>
<br>
<div id="container"><div id="number">
        <div id="first1">
            <?php
            if(isset($msg))
            echo '<h2>'.$msg.'</h2>';
            ?>
            <form action="" method="post">
                <table id="ltable"> 
                    <tr ><th colspan="2" align="center"> <u>* LOGIN *</u> </th></tr>
                    <tr> <td align="right" >USERNAME    : </td><td><input type="text" size="25" name="fname" autofocus required></td></tr>
                    <tr> <td align="right" >PASSWORD   : </td><td><input type="password" size="25" name="password" required></td></tr>
                 <!-- <tr> <td align="right">  DEPARTMENT :</td><td><select name="department">
                                            <option>SELECT</option>
                                            <option>MCA</option>
                                            <option>BCA</option>
                                            <option>MSC.STATS</option>
                                            <option>MSC.MATHS
                                            </option>
                            </select></td></tr>
               -->
                    <tr><td colspan="2" align="center"><input  type="submit" name="submit" value="LOGIN"></td></tr>
                </table>
        </form> 
        <h3>  <pre>

                                                Forgotten UserName?<a href="forget.php" align="center">click here</a>
                                                                                
                                                Don't have an account<a href="uregistration.php" >REGISTER NOW</a></pre> </h3>
        </div>
    </div>
    
    
</div>
<?php
include 'footer.php';
?>
#3session.php
<?php 
    session_start();
   $check_user=$_SESSION['name'];
   $ses_sql=  mysql_query("SELECT * FROM mca WHERE fname='$check_user'");
   $row=  mysql_fetch_array($ses_sql,MYSQL_ASSOC);
   $login_session=$row['fname'];
   if(!isset($_SESSION['name']))
    {
        header('location:login.php');
    }
?>
#4adminaction.php
<?php
include 'include/admin/header.php';
include 'connectdb.php';
include 'session.php';
?>
<div id="container">
    <div id="number">
        <div id="first1">
   
  
            <?php
             echo '<h1>'.'welcome'.$login_session.'</h1>';
            echo 'welcome to admin page you will see different views';
            ?>
            <pre>
                                             <h2>  <a href="logout.php"> LOGOUT</a></h2>

            </pre>
            
        </div>
        
    </div>
    
</div>
<?php
include 'include/admin/footer.php';
?>
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900