0

I'm a designer and not developer, so I don't even know HOW to ask this question.

I have a select box in my script and it shows only one user type. But I need it to show more user types, for example, user_type 2, but Ive tried adding AND / OR and it doesnt work.

Heres the script code.

$result = mysql_query ('SELECT id,email,username FROM ' . $dbacct . '
WHERE user_type="3" ORDER BY username ASC', $link) or die(mysql_error());

Heres the full line

<select class=\'widtha\' name=\'contact_user\'>
                ';
                $result = mysql_query ('SELECT id,email,username FROM ' . $dbacct . ' WHERE user_type IN ("2","3") ORDER BY username ASC', $link) or die(mysql_error());

                while ($row = mysql_fetch_array ($result))
                {
                    $row = safe_data ($row, 'display');
                    echo '<option value=\'' . $row['email'] . '\'';
                    if ($row[id] == $_POST[contact_user])
                    {
                        echo ' selected=\'selected\'';
                    }

                    echo '> ' . $row['username'] . '</option>';
                }
                echo '</select>

Please can someone help me. Anton

5
  • For one thing, you're escaping single quotes in your entire code. Instead of <select class=\'widtha\' name=\'contact_user\'> you should be doing <select class='widtha' name='contact_user'> and do the same for the rest. You only need to escape double quotes when echoing/wrapping in single quotes. Commented Sep 28, 2013 at 14:15
  • This for example echo ' selected=\'selected\''; should be echo 'selected=\"selected\"'; Commented Sep 28, 2013 at 14:15
  • This line echo '> ' . $row['username'] . '</option>'; will definitely give you a hard time with the '> and this echo '</select> should be echo '</select>'; at best. I suggest you find and study PHP tutorials on how to echo, and the use of single and double quotes. An hour of reading will definitely help you to have a bit of developing "blood" into you ;-) Commented Sep 28, 2013 at 14:25
  • Instead of ' . $dbacct . ' you should be doing '" . $dbacct . "' Commented Sep 28, 2013 at 14:25
  • Thank you for the tips, I'll have a look. Commented Sep 28, 2013 at 15:05

1 Answer 1

1
$result = mysql_query ('SELECT id,email,username FROM ' . $dbacct . '
WHERE user_type IN ("1","2","3",....) ORDER BY username ASC', $link) or die(mysql_error());
Sign up to request clarification or add additional context in comments.

2 Comments

Hi Aaron, thank you, must be honest, that didn't work. Even though I removed .... after "3," I got a php script error on line 166
It seems Im not getting the error now, BUT it does not give me 2 options in the select list, if I make it "2", "3"

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.