0

I am new here, and quite new to PHP. I have done a bit of searching for a solution to my problem but none of the cases I find are quite like mine.

I am attempting to feed database values into a HTML drop down box, but I need very specific rows from my database.

Atm my code looks like this:

$query ="SELECT Email FROM circle WHERE Circle_num=$circle_num";
    $query_get = mysql_query($query,$conn);
    if(!$query_get) {
  die("Unable to execute query $query" );
  }

    echo "<select name='circle_users'>";
    while ($temp = mysql_fetch_assoc($query_get)) {
        echo "<option value='".$temp['Email']."'>";
        $temp_email = $temp['Email'];
        $temp_query = "SELECT firstname, lastname FROM user WHERE email=$temp_email";
        if(!$temp_query) {
            die("Unable to execute query $temp_query");
            }
        $get_temp_query = mysql_query($temp_query,$conn);
        $temp2 = mysql_fetch_assoc($get_temp_query);
        echo $temp2['fistname']." ".$temp2['lastname']."</option>";
        }
    }

Sorry about the bad variable names. I am in a little bit of a hurry to finish this.

Jake Ayres
  • 11
  • 2
  • You have write your code in else statement instead of out of condition so you can easily got the problem – Hkachhia Oct 25 '12 at 12:01
  • @Harry it `die`s if the condition passes, so there's not compulsory to add `else`. – Alvin Wong Oct 25 '12 at 12:02
  • @AlvinWong I know that but this is not proper a way of error handling so i have suggest him. – Hkachhia Oct 25 '12 at 12:05
  • Possible duplicate [mysql_fetch_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select?answertab=votes#tab-top). – John Conde Jul 15 '13 at 17:32

2 Answers2

3
$temp_query = "SELECT firstname, lastname FROM user WHERE email=$temp_email";
if(!$temp_query) {
    die("Unable to execute query $temp_query");
}
$get_temp_query = mysql_query($temp_query,$conn);

You're testing the query string here, not the result of mysql_query.
And the query seems to be failing => $get_temp_query is false => expects parameter 1 to be resource, boolean given

VolkerK
  • 95,432
  • 20
  • 163
  • 226
  • Thank you so much. I find it is very easy to miss small things when you are new to PHP and have been staring at the same code for hours. – Jake Ayres Oct 25 '12 at 12:06
  • To elaborate on the last part of @VolkerK's answer, there's probably something wrong with your SQL. From looking at your code I would guess it's because you're not encapsulating $temp_email in single quotes. – Chris Carson Oct 25 '12 at 12:15
  • Yes, that was the main issue. @Xyon was kind enough to point that out to me. – Jake Ayres Oct 25 '12 at 12:31
2

I think

$temp_query = "SELECT firstname, lastname FROM user WHERE email=$temp_email";

Should probably be

$temp_query = "SELECT firstname, lastname FROM user WHERE email='$temp_email'";

The error you're getting from fetch_assoc indicates that your query did not execute successfully.

Xyon
  • 901
  • 9
  • 18
  • Thank you for the help. This was one of the main problems in the code, as well as a variable name being mispelled. – Jake Ayres Oct 25 '12 at 12:09