www.webdeveloper.com
Results 1 to 2 of 2

Thread: "Query was empty"...

Hybrid View

  1. #1
    Join Date
    Jun 2006
    Location
    Doncaster
    Posts
    78

    "Query was empty"...

    Hi,
    I have a script to fetch data from mysql into PHP.

    I've logged in a user, using first and second names which are sent as session variables.
    I then need to confirm he/she has admin rights, which is recorded in a field on the database.

    So the PHP looks like this:
    PHP Code:
    <?php
    session_start
    ();
    if((!
    $_SESSION["first_name"])&&(!$_SESSION["second_name"])){
    header("location:login.php");
    }
    //DB login
        
    require_once('mysql_login.php');
        
    $query "SELECT * FROM cast WHERE fname='$_SESSION[first_name]' and sname='$_SESSION[second_name]'";
        
    $result=mysql_query($sql) or die(mysql_error());
    $newArray mysql_fetch_array($result);
    $level $newArray['role'];
    if (
    $level=="admin")    {
    echo 
    "Sorry, you need to be an admin to access this page";
    }
    ?>
    ...which is returning a "query was empty" message.

    The variables were registered on a different login page as:
    PHP Code:
    $myfirstname=$_POST['myfirstname'];
    $mysecondname=$_POST['mysecondname'];
    $_SESSION[first_name] = $myfirstname;
    $_SESSION[second_name] = $mysecondname
    Hints or pointers - all appreciated!

  2. #2
    Join Date
    Jun 2007
    Posts
    191
    What is this line referencing:

    PHP Code:
    $result=mysql_query($sql) or die(mysql_error()); 
    I think it should read:

    PHP Code:
    $result=mysql_query($query) or die(mysql_error()); 

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles