Rifts Posted November 26, 2009 Share Posted November 26, 2009 after submitting my dropdown box form i get Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in C:\wamp\www\homepage\google.php on line 146 the php form im getting $_POST from (the dropdown box): <form id="loginForm" name="drop" method="post" action="google.php"> <?php mysql_connect('localhost','root',''); if (!isset($_POST['email'])) { $q = mysql_query("SELECT * FROM members"); echo "<select name='email'>"; while ($row = mysql_fetch_assoc($q)) { echo "<option value='{$row['email']}'>{$row['firstname']}</option>"; } echo "</select>"; }else { print_r($_SERVER); print_r($_POST); } ?> <input type="submit" name="submit" value="Submit Now" /> and here is the php file which is giving my the error: <?php mysql_connect('localhost','root',''); if (!isset($_POST['email'])) { $q = mysql_query("SELECT * FROM members"); echo "<select name='email'>"; while ($row = mysql_fetch_assoc($q)) { echo "<option value='{$row['email']}'>{$row['firstname']}</option>"; } echo "</select>"; }else { $row = mysql_fetch_assoc(mysql_query("SELECT * FROM members WHERE firstname = '{$_POST['email']}'")); print_r($row); } ?> like 146 is $row = mysql_fetch_assoc(mysql_query("SELECT * FROM members WHERE firstname = '{$_POST['email']}'")); Thanks Quote Link to comment https://forums.phpfreaks.com/topic/183063-mysql_fetch_assoc-error-help-please/ Share on other sites More sharing options...
KevinM1 Posted November 26, 2009 Share Posted November 26, 2009 You have to select the db you want to use before accessing its tables. See: mysql_select_db Quote Link to comment https://forums.phpfreaks.com/topic/183063-mysql_fetch_assoc-error-help-please/#findComment-966154 Share on other sites More sharing options...
Rifts Posted November 26, 2009 Author Share Posted November 26, 2009 I cant figure out where to put mysql_select_db("clients"); in that second code to make it work? Quote Link to comment https://forums.phpfreaks.com/topic/183063-mysql_fetch_assoc-error-help-please/#findComment-966160 Share on other sites More sharing options...
premiso Posted November 27, 2009 Share Posted November 27, 2009 <?php mysql_connect('localhost','root',''); mysql_select_db("clients"); if (!isset($_POST['email'])) { $q = mysql_query("SELECT * FROM members"); echo "<select name='email'>"; while ($row = mysql_fetch_assoc($q)) { echo "<option value='{$row['email']}'>{$row['firstname']}</option>"; } echo "</select>"; }else { $row = mysql_fetch_assoc(mysql_query("SELECT * FROM members WHERE firstname = '{$_POST['email']}'")); print_r($row); } ?> Should do it. Quote Link to comment https://forums.phpfreaks.com/topic/183063-mysql_fetch_assoc-error-help-please/#findComment-966267 Share on other sites More sharing options...
Rifts Posted November 27, 2009 Author Share Posted November 27, 2009 ok im not getting any errors anymore which is a step up haha but im just not getting anything print_r($row); shows nothing as does echo $row; Quote Link to comment https://forums.phpfreaks.com/topic/183063-mysql_fetch_assoc-error-help-please/#findComment-966283 Share on other sites More sharing options...
premiso Posted November 27, 2009 Share Posted November 27, 2009 Well let me throw this out there, in your SQL you are checking firstname against email...should you be checking email against email? Quote Link to comment https://forums.phpfreaks.com/topic/183063-mysql_fetch_assoc-error-help-please/#findComment-966284 Share on other sites More sharing options...
Rifts Posted November 27, 2009 Author Share Posted November 27, 2009 yeah it doesn't matter It didnt work with "email" so I was just trying out other columns in my db humm idk what to do Quote Link to comment https://forums.phpfreaks.com/topic/183063-mysql_fetch_assoc-error-help-please/#findComment-966289 Share on other sites More sharing options...
Rifts Posted November 27, 2009 Author Share Posted November 27, 2009 wait i just realized this code is trying to make a dropdown box (the second code) thats not what I want at all... I was just trying to display values from my database but i cant figure it out Quote Link to comment https://forums.phpfreaks.com/topic/183063-mysql_fetch_assoc-error-help-please/#findComment-966290 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.