Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Login script simply wont work....

    Ok, im quite new to php. I have a tutorial booklet that helped me code this, however it wont work, its supposed to redirect me to admincp.php when i successfully login, and redirect back to index when login fails. However it only ever redirects to index.


    here:

    index:
    PHP Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <
    html xmlns="http://www.w3.org/1999/xhtml">
    <
    head>
    <
    meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <
    title>mysite</title>
    <
    script language="javascript">
    function 
    Validate(){
        var 
    username document.frmLogin.txtUsername.value;
        var 
    lenusername username.length;
        var 
    password document.frmLogin.txtPassword.value;
        var 
    lenpassword password.length;
        if(
    username <1) {
            
    alert("Please enter your username.");
            
    document.frmLogin.txtUsername.value "");
            return 
    false;
        }
        else if(
    lenpassword <1) {
            
    alert("Please enter your passowrd.");
            
    document.frmLogin.txtPassword.value "");
            return 
    false;
        }
        else {
            
    frmLogin.Submit.disabled true;
            return 
    true;
        }
    }
    </script>
    // ----------------------------------------------------------------------\
    // Tom's Website                                                          |
    // Copyright 2009 GFX-Core                                                  |
    //                                                                          |
    // Redistribution prohibited without written permission                      |
    // ______________________________________________________________________/
    </head>

    <body>
    <H3>My Website</h3>
    <br/>
    <table>
        <form name="frmLogin" action="login.php" method="post" onSubmit="return Validate()">
        <input type="hidden" value="agentlogin" />
        <tr>
            <td><input name="txtUsername" type="text" id="txtUsername" maxlength="30" />
            Username</td>
        </tr>
        <tr>
            <td><input name="txtPassword" type="password" id="txtPassword" maxlength="10" />
            Password </td>
         </tr>  
        <tr>
            <td><input type="submit" name="submit" value="Login" /></td>
        </tr>
        </form>
    </body>
    </html> 
    Login.php:
    PHP Code:
    <?php
    include("inc/config.php");

    session_start();
    header("Cache-control: private");
    $username trim($_POST['txtUsername']);
    $password trim($_POST['txtPassword']);
        if (
    $username != "" && $password != "") {

    //Connect to Database
         
    $db mysql_connect("$dbhost, $dbuser, $dbpass");
         
    mysql_select_db("$dbname, $db");
        
    $sql "SELECT * FROM users WHERE username ='" .$username."'AND password ='" .$password."'";
        
    $result mysql_query($sql);
    //Count number of records
        
    $num=mysql_num_rows($result);
        if(
    $num==0){
                
    //close DB
                
    mysql_close();
                
    //then redirect to index
                
    header("Location: index.php");
        }
        else {
            
    //login ok!
            
    $_SESSION['ID'] = mysql_result($result,0,"ID");
            
    //go to menu
            
    header("Location: admincp.php");
        }
        
    //close database
        
    mysql_close();
    }
        else{
            
    $_SESSION['ID'] ="";
        
    header("Location: index.php");
        }
    ?>
    Herlp would be appreciated
    Last edited by tommykent1210; 10-29-2009 at 11:53 PM.

  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    $num=mysql_numrows($result);

    to

    $num=mysql_num_rows($result);

    for a start
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #3
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    ok, fixed. still doesnt solve the probelm... Is the include config.php file bit correct?

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    This is wrong
    PHP Code:
    $db mysql_connect("$dbhost, $dbuser, $dbpass");
         
    mysql_select_db("$dbname, $db"); 
    It should be
    PHP Code:
    $db mysql_connect($dbhost$dbuser$dbpass);
         
    mysql_select_db($dbname$db); 
    Learn to follow the tutorial better. I doubt it told you to put all of those in quotes. Also there is a of other stuff wrong. The main thing I see is you aren't protecting yourself from mysql_injection and sooner or later you site will likely get hacked.

    http://www.tizag.com/mysqlTutorial/m...-injection.php
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    dont know... change it to

    PHP Code:

    $dir 
    "inc/config.php";
    if(
    file_exists($dir))
    {
        include(
    $dir);
    }
    else
    {
        echo 
    "dir does not exist";

    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #6
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    change

    PHP Code:
    $result mysql_query($sql); 
    to

    PHP Code:
    $result mysql_query($sql) or die("Error: ".mysql_error()); 
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #7
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    It seems that it wont connect to the mysql. It says;

    Code:
    Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'nobody'@'10.50.0.58' (using password: NO) in /home/a9541859/public_html/mysite/login.php
    yet the password is being used, it just doesnt seem to recognise it....

  • #8
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    then:
    Code:
    Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host 'MYWEBHOSTMYSQL, MYSQLUSERNAME, PASSWORD' (3) in /home/a9541859/public_html/mysite/login.php
    obviously i have removed my details

  • #9
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    ("$dbhost, $dbuser, $dbpass");

    to


    ($dbhost, $dbuser, $dbpass);
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 

  • #10
    New to the CF scene
    Join Date
    Oct 2009
    Posts
    9
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ah-ha! that worked, thanks better correct this book then lol, written for A-level and ive found 3 mistakes already

  • #11
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    no worries
    Website Design Mansfield
    PHP Code:
    function I_LOVE(){function b(&$b='P'){$b.='P';}function a($_){return $_++;}$b='P';define("B",'H');b($b=implode('',array($b=a($b),$b=a(B))));b($b);return $b;}
    echo 
    I_LOVE(); 


  •  

    Posting Permissions

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