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 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2008
    Posts
    446
    Thanks
    23
    Thanked 5 Times in 5 Posts

    mysqli - Unknown column 'admin' in 'where clause'

    I am getting a weird error saying that I am trying to look under a column 'admin'. I have built this function in the past without a problem, but this time I get this error. Here is my code:

    PHP Code:
    function search_user($type$user_pass)
    {
        
    $Database = new mysqli(#############);

        
    mysqli_report(MYSQLI_REPORT_ERROR);
        
        
    $view_type 'view_'.$type;

        
    //query database
        
    if($stmt $Database->query("SELECT ".$view_type." FROM views WHERE view_pass=".$user_pass.""))
        {
            
    $show $stmt->fetch_object();
            return 
    $show->$view_type;    
            
    $stmt->close();
        }
        else
        {
            echo 
    'Error: could not prepare SQL statement.<br />';
        }

    $user_pass = 'admin'
    $view_type = 'view_priv' (another column, if that wasnt too obvious )
    view_pass is the column I am trying to search under. Any idea what is going on here?

    Thanks a lot

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    If you were to echo your query, you'd probably immediately see the problem.
    PHP Code:
    $query "SELECT ".$view_type." FROM views WHERE view_pass=".$user_pass."";
     if(
    $stmt $Database->query($query))
     {
            
    $show $stmt->fetch_object();
            return 
    $show->$view_type;    
            
    $stmt->close();
        }
        else
        {
            echo 
    'Error: could not prepare SQL statement.<br />Query: $query<br />Error: '.$Database->error;
        } 
    You are not enclosing your string "admin" in single quotes in your query, so it's coming out as WHERE view_pass=admin and MySQL is regarding admin as a column name, which it doesn't find in your table, thus your error. Your query should be coded with single quotes: WHERE view_pass='admin'


  •  

    Posting Permissions

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