-1

For the user I am testing with, their org_id column value is "student_life"

I am trying to have this function display whatever rows have the student_life column = 1. (so yes there is a column student_life which is a boolean, and then I also have a separate column named org_id and in this case has the value student_life)

I am pretty sure there is a syntax error but I cannot figure it out.

function org_id_users_table() 
{
$org_id = mysql_real_escape_string($_POST["org_id"]);

$sql = $this->query("SELECT * FROM ".DBTBLE." WHERE '$org_id' = '1'");
$result = $sql['sql'];
$num_rows = $sql['num_rows'];
$this->create_table($result, $num_rows);
}

(when I replace $org_id in the "$sql=..." line with student_life the code works.

3 Answers3

1

You're quoting the column name, which makes MySQL think it's a string.

$sql = $this->query("SELECT * FROM ".DBTBLE." WHERE $org_id = '1'");

Edit:

Based on your comments, I think what you actually want is this:

$sql = $this->query("SELECT * FROM ".DBTBLE." WHERE org_id = '$org_id'");
Mark Parnell
  • 9,175
  • 9
  • 31
  • 36
  • That will make the query run as expected (assuming `DBTBLE` is defined and `$org_id` has the expected value). What that function actually returns will depend on what `$this` is. Are you seeing any errors? When you say it doesn't work, what exactly does that mean? Which part doesn't work? – Mark Parnell Apr 19 '13 at 01:08
  • I've narrowed the problem down to the first part where I am giving '$org_id' a value. For the user I am signed into, the org_id column in mysql is student_life. When I manually input '$org_id='student_life'' it works. – user2296393 Apr 19 '13 at 01:28
  • The value for $org_id needs to be pulled from the database column, org_id . That's what I'm having trouble with. – user2296393 Apr 19 '13 at 01:31
  • Huh? You're using the value of `$org_id` as the column name. You're saying now that's not what you want to do? – Mark Parnell Apr 19 '13 at 01:37
  • Sorry for the confusion, I am trying my best. I would like the value of my column, `org_id` to become the value of my newly created variable, `$org_id` – user2296393 Apr 19 '13 at 01:41
0

Change quotes.

$sql = $this->query("SELECT * FROM ".DBTBLE." WHERE `$org_id` = '1'");

P.S. Why shouldn't I use mysql_* functions in PHP?

Community
  • 1
  • 1
sectus
  • 15,605
  • 5
  • 55
  • 97
0

Where is this coming from? $_POST["org_id"]

Do you have a form on the page posting that? Or are you just trying to get that from the database? If so, wouldn't you need another query to obtain that first?

$row_MyFirstQuery['org_id']

Otherwise if it is $_POST["org_id"], wouldn't it be single quotes not double? $_POST['org_id']

Andre
  • 1