Log in

View Full Version : Resolved SELECT issue



AdrielGreene
04-23-2009, 08:56 PM
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.

Schmoopy
04-23-2009, 09:20 PM
Try adding single quotes around the variable name:


"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.

AdrielGreene
04-24-2009, 01:57 AM
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.


<?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!

borris83
04-24-2009, 10:29 AM
Try the following in line 32


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

AdrielGreene
04-24-2009, 02:44 PM
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.