Results 1 to 5 of 5

Thread: SELECT issue

  1. #1
    Join Date
    Mar 2009
    Location
    NJ, USA
    Posts
    32
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default SELECT issue

    That stopped the error!

    But now nothing displays. I was testing the connection, I'll keep trying with that for now. Thank you Borris.

    I am going to create a new thread because this thread is changing topic.
    Last edited by AdrielGreene; 04-24-2009 at 04:42 PM.

  2. #2
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    Try adding single quotes around the variable name:

    PHP Code:
    "SELECT `professional` FROM users WHERE `sub_domain` = '$prac_dir'"
    Just a quick suggestion, try it and see, good luck

    Edit: You should also get into the habit of putting ticks around your column names like I have above, this is useful if there is a reserved word that is the same as one of the column names.

  3. The Following User Says Thank You to Schmoopy For This Useful Post:

    AdrielGreene (04-24-2009)

  4. #3
    Join Date
    Mar 2009
    Location
    NJ, USA
    Posts
    32
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    OK! no more error with the single quotes. but now I have an evolved problem. I want to echo from the array I've created.

    Code:
    <?php
    $prac_dir = basename(dirname(__FILE__));
    
    include ('/home/Myusername/Mywebsite.com/config.inc.php');
    
    include (MYSQL);
    $q = "SELECT 'professional' FROM users WHERE 'sub_domain' = '$prac_dir'";
    $r = mysqli_query ($dbc, $q) or trigger_error("Query: $q\n<br />MySQL Error: " . mysqli_error($dbc));
    $_display = mysqli_fetch_array ($r, MYSQLI_ASSOC);
    
    echo "$_display['professional']"; 
    ?>
    And this error appears:
    Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING on line 32

    Line 32 is echo "$_display['professional']";

    I'm assuming that means there is no value in my array. Is this correct? I'll try playing around with my config file and how I connect for now. Thanks for your input!

  5. #4
    Join Date
    Mar 2009
    Location
    Chennai, India
    Posts
    77
    Thanks
    16
    Thanked 7 Times in 6 Posts

    Default

    Try the following in line 32

    Code:
    echo $_display['professional']
    It will definitely work (remove the quotes)
    This is strange anyway, because

    If you assign $something = "something";
    and type echo "$something"; in your code it works...


    But if you assign $something['something'] = "something";
    and use echo "$something['something']" , you will get the exact error....


    Check here:
    http://bugs.php.net/bug.php?id=28148

  6. The Following User Says Thank You to borris83 For This Useful Post:

    AdrielGreene (04-24-2009)

  7. #5
    Join Date
    Mar 2009
    Location
    NJ, USA
    Posts
    32
    Thanks
    8
    Thanked 0 Times in 0 Posts

    Default

    That stopped the error!

    But now nothing displays. I was testing the connection, I'll keep trying with that for now. Thank you Borris.

    I am going to create a new thread because this thread is changing topic.
    Last edited by AdrielGreene; 04-24-2009 at 04:39 PM.

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
  •