tags:

views:

40

answers:

4

can some assist me with my code, everything looks correct checked each line at least 10 times. I've even hardcode in the user/pass for the query and still nothing.

<?php
include "database.php";

$sql = "SELECT UserName, Password, Language, Editor FROM admin_login WHERE UserName='".$_POST['username']."' AND Password='".$_POST['pwd']."'";

$result = @mysql_query($sql);
$line = @mysql_fetch_assoc($result);

    if (mysql_num_rows($result) == 0) {
#unsuccessful login
    header('Location: index.php' ); 
    } else {

#login successful, setting up session
    ob_clean();
session_start();
        $_SESSION['user'] = $line['UserName'];
        $_SESSION['pass'] = $line['Password'];
        $_SESSION['lang'] = $line['Language'];
        $_SESSION['editor'] = $line['Editor'];

#send to editor page        
            if ($_SESSION['lang'] == 'List') {
                header('Location: list.php');
                exit;

#send to announcer page   
            } else if ($_SESSION['lang'] == 'Order') {
                header('Location: order.php');
                exit;
            }
}
?>
+3  A: 

remove the @ from the function mysql_query and from mysql_fetch_assoc and you will have the errors displayed.

Bladedu
+1  A: 

Some steps to follow:

  1. Add MySQL error reporting such as (to the end of your SQL statement):

    or die ("Query failed: " . mysql_error() . " Actual query: " . $query)

  2. Remove the @ symbols -- these suppress errors.

  3. Run your query on the command line with your favorite SQL tool (phpMyAdmin, Navicat, Command line, etc) to see if it results in an error
bpeterson76
sql processed correctly in phpmyadmin 1 result found, removed @ and no errors
acctman
+1  A: 

Here's my version:

<?php

include 'database.php';

$sql = "SELECT `UserName`, `Password`, `Language`, `Editor` FROM `admin_login` WHERE `UserName` = '" . mysql_real_escape_string($_POST['username']) . "' AND `Password` = '" . mysql_real_escape_string($_POST['pwd']) . "' LIMIT 1;";

$result = mysql_query($sql);

if ($result === false)
{
    // Unsuccessful Login
    header('Location: index.php');
}

$user = mysql_fetch_assoc($result);

$_SESSION['user'] = $user;

if ($user['Language'] == 'List')
{
    header('Location: list.php');
    exit;
}
elseif ($user['Language'] == 'Order')
{
    header('Location: order.php');
    exit;
}

?>

If it still shows some errors copy/paste them here, if no errors are displayed and code still don't works then show us your database scheme and a database.php file.

Otar
I see my error now... $user['Language'] is suppose to be Editor field that's what my original coding kept displaying blank. All the coding was correct it just was looking it the wrong field. thanks you're coding helped me notice my error.
acctman
+1  A: 

As already stated, remove all the @ prefixes from functions. That suppresses all the errors.

Additionally, add the following two lines to the start of your script:

error_reporting(E_ALL);
ini_set('display_errors','1');
Pelle ten Cate
added that, no errors are displayed used error_reporting(E_ALL);
acctman
Aargh, you're right, typo. Fixed it.
Pelle ten Cate