SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    Posts
    731
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    Query Looks For Column - Very Peculiar

    Hi,

    I am finding a very strange result from a query I am trying to perform.

    The roomname is office (.php?roomname=office)

    The word office is echoed as per the first echo of the below code. However instead of searching the column 'room' for the word 'office' in table furniture_groups it returns an message saying that the column 'office' is not in the table. However it shouldn't be searching for a column, it should querying the column called room.

    Any suggestions please?


    Code:
    <?php
    
    $roomname = mysql_real_escape_string($_GET['roomname']);
    
    echo $roomname; 
    
       $sql = "SELECT * FROM furniture_groups WHERE room = $roomname";
        $res = mysql_query($sql) or die(mysql_error());
        $row = mysql_fetch_assoc($res); // no need to loop since you are retrieving only one row
    
    
    echo $row['long_name']; 
    
    ?>

  2. #2
    SitePoint Enthusiast
    Join Date
    Jul 2013
    Location
    Voorheesville NY USA
    Posts
    88
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You must put $roomname in single quotes.


Bookmarks

Posting Permissions

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