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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP login redirect error

    Hey all,

    Having trouble with a php login. The login process itself is not failing. I have a tbl_auth_user with the login info inside my database and it views it and authenticates perfectly, thanks to somebodies words of wisdom here. The issue I have is on successful login it goes to a blank screen and still looks as if its on the login page (still shows xxx.xxx/englogin.php). If anyone can let me know what I did wrong I would appreciate it!! Here is the page script::

    <?php
    // we must never forget to start the session
    session_start();

    $errorMessage = '';
    if (isset($_POST['txtUserId']) && isset($_POST['txtPassword'])) {
    include 'opendb.php';
    include 'config.php';

    $userId = $_POST['txtUserId'];
    $password = $_POST['txtPassword'];

    // check if the user id and password combination exist in database
    $sql = "SELECT user_id
    FROM tbl_auth_user
    WHERE user_id = '$userId' AND user_password = PASSWORD('$password')";

    $result = mysql_query($sql) or die('Query failed. ' . mysql_error());

    if (mysql_num_rows($result) == 1) {
    // the user id and password match,
    // set the session
    $_SESSION['db_is_logged_in'] = true;

    // after login we move to the main page
    header('Location: enggui.html');
    exit;
    } else {
    $errorMessage = 'Sorry, wrong user id / password';
    }

    include 'closedb.php';
    }
    ?>
    <html>
    <head>
    <title>Engineering Login</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>
    <center><img src="ABC_FOX Logos.JPG" width="156" height="44"></center>
    <body>

    <?php
    if ($errorMessage != '') {
    ?>
    <p align="center"><strong><font color="#990000">
    <?php echo $errorMessage; ?></font></strong></p>

    <div align="center">
    <?php
    }
    ?>
    </div>
    <form action="" method="post" name="frmLogin" id="frmLogin">
    <table width="400" border="1" align="center" cellpadding="2" cellspacing="2">
    <tr>
    <td width="150">User Id</td>
    <td><input name="txtUserId" type="text" id="txtUserId"></td>
    </tr>
    <tr>
    <td width="150">Password</td>
    <td><input name="txtPassword" type="password" id="txtPassword"></td>
    </tr>
    <tr>
    <td width="150">&nbsp;</td>
    <td><input name="btnLogin" type="submit" id="btnLogin" value="Login"></td>
    </tr>
    </table>
    </form>
    </body>
    </html>

  • #2
    Senior Coder CFMaBiSmAd's Avatar
    Join Date
    Oct 2006
    Location
    Denver, Colorado USA
    Posts
    2,958
    Thanks
    2
    Thanked 304 Times in 296 Posts
    There are two possibilities. The header is not being sent or the location URL is not the correct format or does not exist.

    For the first possibility, add the following lines after your first opening <?php tag -
    PHP Code:
    ini_set ("display_errors""1");
    error_reporting(E_ALL); 
    For the second possibility, the URL in a header redirect technically needs to be a full/absolute URL (relative URL's work depending on browser type and version) -
    PHP Code:
    header('Location: http://yourdomain.com/enggui.html'); 
    If you are learning PHP, developing PHP code, or debugging PHP code, do yourself a favor and check your web server log for errors and/or turn on full PHP error reporting in php.ini or in a .htaccess file to get PHP to help you.

  • #3
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    OK, so after entering your script and adjusting the destination of enggui.html to read the full http://mydomain.com/enggui.html, I get the following error when initially bringing up the login page:

    Warning: Unknown(): open(/var/lib/php/session/sess_de79ce8275ea6187eafa8c47e26188a2, O_RDWR) failed: Permission denied (13) in Unknown on line 0

    Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0

    Once I enter a valid user, I get redirected to the blank page where I see the following error:

    Query failed. No database selected
    Warning: Unknown(): open(/var/lib/php/session/sess_de79ce8275ea6187eafa8c47e26188a2, O_RDWR) failed: Permission denied (13) in Unknown on line 0

    Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/var/lib/php/session) in Unknown on line 0

  • #4
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    So I managed to get rid of all those errors, and now when i enter a valid user, I go to a blank page that says, Query failed. No database selected. Thats it, no redirect to the enggui.html and I am not sure why its asking for a database cause it should just be going to this page where parts can be looked up.

    I am not very good at this php as you can all see by now. Thanks though for any assistance and for previous assistance as well.

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,638
    Thanks
    2
    Thanked 404 Times in 396 Posts
    Check opendb.php & config.php and make sure your database information is correct, in particular mysql_select_db() and the $variable it uses(if any).

  • #6
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Inigoesdr View Post
    Check opendb.php & config.php and make sure your database information is correct, in particular mysql_select_db() and the $variable it uses(if any).


    OK, so here is my opend:

    <start>
    $dbhost = 'localhost';
    $dbuser = 'fakeuser';
    $dbpass = 'password';
    $dbname = 'the dbname';
    mysql_select_db($dbname);
    $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
    <end opend>

    And my config:

    <start>
    $dbhost = 'localhost';
    $dbuser = 'fakeuser';
    $dbpass = 'password';
    $dbname = 'the dbname';
    <end config>

    I feel as though I am missing something somewhere but am not very adept at this yet.

  • #7
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    You have to connect to the db before you select it
    PHP Code:
    $conn mysql_connect($dbhost$dbuser$dbpass) or die ('Error connecting to mysql');
    mysql_select_db($dbname,$conn); 

  • #8
    New to the CF scene
    Join Date
    Jan 2007
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Well that didn't seem to do anything either. I am wondering if I shouldn't just re-evaluate my needs and do something a little different. Thanks all for the help though.


  •  

    Posting Permissions

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