SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: login script

  1. #1
    SitePoint Addict
    Join Date
    Dec 2011
    Posts
    221
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)

    login script

    Greetings!

    I'm using mootols.js to show my validations, and I got it working to show the errors.
    My problem is when I put the right username and password it doesn't redirect to its page.

    login.html
    Code:
    <?php
    include "include/session.php";
    include "include/z_db.php";
    ?>
    <!doctype html public "-//w3c//dtd html 3.2//en">
    <html>
    <head>
    <title></title>
    <script type="text/javascript" src="../js/mootools.js"></script>
    	<script type="text/javascript">
    		window.addEvent('domready', function(){
    	                $('registerForm').addEvent('submit', function(e) {
    	                    new Event(e).stop();
    	                    var log = $('log_res').empty().addClass('ajax-loading');
    	                    this.send({
    	                        update: log,
    	                        onComplete: function() {
    	                            log.removeClass('ajax-loading');
    	                        }
    	                    });
    	                });
    	            });
    	</script>
    </head>
    <body>
    <form id ="registerForm"  action = "loginck.php" method = "post">
    <table>
    login ID: <input type ='text' class='bginput' name='userid' id='userid' ></font></td></tr>
    Password: <input type ='password' class='bginput' name='password' ></font></td></tr>
    <input type='submit' value='Submit' /> 
    </table></center>
    </form>
    <div id="log">
    		<div id="log_res">
    		<!-- SPANNER -->
    		</div>
    		</div>
    </body>
    </html>
    loginck.php
    PHP Code:
    <?php
    include "include/session.php";
    include 
    "include/z_db.php";

    $userid=$_POST['userid'];
    $password=$_POST['password'];

    ?>

    <?php
    $userid
    =mysql_real_escape_string($userid);
    $password=mysql_real_escape_string($password);


    if(
    $rec=mysql_fetch_array(mysql_query("SELECT * FROM tbl_admin WHERE admin_uname ='$userid' AND admin_Password = '$password'")))
    {
        if((
    $rec['admin_uname']==$userid)&&($rec['admin_Password']==$password))
        {
        
    //include "include/newsession.php";
        
    $user 'admin';
        }
    }
    if(
    $rec=mysql_fetch_array(mysql_query("SELECT * FROM tbl_faculty WHERE fac_Id ='$userid' AND fac_Password = '$password'")))
    {
        if((
    $rec['fac_Id']==$userid)&&($rec['fac_Password']==$password))
        {
        
    //include "include/newsession.php";
        
    $user 'faculty';
        }
    }
    else { 
    echp 'Invalid user name and pass';}
          
    switch(
    $user)
    {
        case 
    "admin";
        echo 
    "<meta http-equiv=\"refresh\"content=\"0;URL=../admin.html\">";    
        break;
        
        case 
    "faculty";
        echo 
    "<meta http-equiv=\"refresh\"content=\"0;URL=../faculty.html\">";
        break;
    }
    Any help is really appreciated. Thank you.

  2. #2
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    First of all, is it true that you have included some PHP files (sessions.php & z_db.php) in your html page? Is sessions.php file for starting the session? That might make hamper on properly functioning. Change HTML file to php i.e. login.html to login.php

    Secondly, why are you using meta refresh for redirection? Do PHP header redirection instead as below:
    PHP Code:
    switch($user)
    {
        case 
    "admin";
            
    header("Location: ../admin.html");
            exit;
            break;
        case 
    "faculty";
            
    header("Location: ../faculty.html");
            exit;
            break;

    Hope that will help to figure out the problems.
    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  3. #3
    SitePoint Addict
    Join Date
    Dec 2011
    Posts
    221
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Thank you very much for the response sir.
    My login page is in login.php ..

    I changed already meta to header but still no work.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •