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.

4
  • You have write your code in else statement instead of out of condition so you can easily got the problem Commented Oct 25, 2012 at 12:01
  • @Harry it dies if the condition passes, so there's not compulsory to add else. Commented Oct 25, 2012 at 12:02
  • @AlvinWong I know that but this is not proper a way of error handling so i have suggest him. Commented Oct 25, 2012 at 12:05
  • Possible duplicate mysql_fetch_array() expects parameter 1 to be resource, boolean given in select. Commented Jul 15, 2013 at 17:32

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

3 Comments

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.
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.
Yes, that was the main issue. @Xyon was kind enough to point that out to me.
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.

1 Comment

Thank you for the help. This was one of the main problems in the code, as well as a variable name being mispelled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.