nacunis Posted May 12, 2011 Share Posted May 12, 2011 I get this message with the code at the bottom: PHP Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home1/acunishi/public_html/go/auth/birthdays_holidays-greetings.php on line 35 session_start(); $connection=mysql_connect("localhost","database username","db user password"); $db=mysql_select_db("database name",$connection ); $users_table = 'table name'; $username = $_POST['myusername']; $result3 = mysql_query("SELECT `nickname` from `databasename`.`tablename` WHERE `loginsv4_md5`.`username` = '$myusername'"); $result4 = mysql_query("SELECT `lastlogin` from `databasename'.'tablename` WHERE `tablename`.`username` = '$myusername'"); $result5 = mysql_query("SELECT `announce` from `databasename`.`tablename` WHERE `tablename`.`username` = '$myusername'"); $num_rows = mysql_num_rows($result3); $row3 = mysql_fetch_assoc($result3); while ($row3 = mysql_fetch_assoc($result3)) { echo " \n <br>"; echo $row3['nickname']; echo " "; echo " \n"; } $row5 = mysql_fetch_assoc($result5); while ($row5 = mysql_fetch_assoc($result5)) { echo $row5['announce']; echo " "; } $row4 = mysql_fetch_assoc($result4); while ($row4 = mysql_fetch_assoc($result4)) { echo $row4['lastlogin']; echo " "; } ..... code not displayed Error message seems to point to mysql_fetch_assoc. Other pieces of this code are being executed, so I know the module is called and executing, and of course, there is the PHP warning message from the log. Please help Quote Link to comment https://forums.phpfreaks.com/topic/236235-variable-association-warning/ Share on other sites More sharing options...
fugix Posted May 12, 2011 Share Posted May 12, 2011 looks to me like you accidently placed single quotes where backticks are needed...try this $result4 = mysql_query("SELECT `lastlogin` from `databasename`.`tablename` WHERE `tablename`.`username` = '$myusername'"); Quote Link to comment https://forums.phpfreaks.com/topic/236235-variable-association-warning/#findComment-1214583 Share on other sites More sharing options...
wildteen88 Posted May 12, 2011 Share Posted May 12, 2011 Why are you performing three queries on the same table and only fetching one field at a time? MySQL can fetch more than one field per query. Also if your query is only going to return one result you do not need to use a while loop. As for the error you need to check whether your queries are returning any errors. You can do this using mysql_error Quote Link to comment https://forums.phpfreaks.com/topic/236235-variable-association-warning/#findComment-1214585 Share on other sites More sharing options...
nacunis Posted May 16, 2011 Author Share Posted May 16, 2011 To responder 1, thank you. It didn't work because the actual code had a backtick. Oh well. 8)8)8) As for responder 2, that code came from a PHP programmer (not me) and it worked. So the question about why I did it that way and not another way was not helpful for me. :(:(:(:( I wouldn't call myself a PHP programmer at all. If the forum results in people debating code rather than being helpful, I'll drop my association with this forum. Again, thanks to responder 1. At least you tried to help rather than debate. 8)8) Quote Link to comment https://forums.phpfreaks.com/topic/236235-variable-association-warning/#findComment-1215838 Share on other sites More sharing options...
fugix Posted May 16, 2011 Share Posted May 16, 2011 glad i could help, if you ever need further assistance we are here to help Quote Link to comment https://forums.phpfreaks.com/topic/236235-variable-association-warning/#findComment-1215841 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.