Marsha Posted December 31, 2010 Share Posted December 31, 2010 Heya, I am making a code that shows users that are on a database with a postid, for each post on my forum, this will run and any username with the current postid will be shown. Problem is, I get an error: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/SITENAME/public_html/SITENAME/forums/likeusers.php on line 9 Heres the code: <font size="1"> <? $postid=$_GET['postid']; $view=$_GET['view']; mysql_connect("localhost", "USERNAME", "PASSWORD") or die(mysql_error()); mysql_select_db("DATABASE") or die(mysql_error()); $result = mysql_query("SELECT username FROM data WHERE postid=$postid"); $rows = mysql_fetch_array($result); < -- LINE 9 $query_multiplecheck = "SELECT username FROM data WHERE postid='$postid'"; $multiplecheck = mysql_query($query_multiplecheck) or die(mysql_error()); $row_multiplecheck = mysql_fetch_assoc($multiplecheck); $totalRows_multiplecheck = mysql_num_rows($multiplecheck); if($view == "1") { } else { if ( $totalRows_multiplecheck > 0 ) { echo $rows[username]; } else { } if ( $totalRows_multiplecheck == "1" ) { echo ' likes this post.'; } else { } if ( $totalRows_multiplecheck == "2" ) { echo ' and ', $totalRows_multiplecheck - "1", ' other like this post. <a href="likeusers.php?=', $postid, '&view=1">View Likes</a>'; } else { } if ( $totalRows_multiplecheck > 2 ) { echo ' and ', $totalRows_multiplecheck - "1", ' others like this post. <a href="likeusers.php?=', $postid, '&view=1">View Likes</a>'; } else { } } ?> </font> Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/223059-mysql_fetch_array/ Share on other sites More sharing options...
Pikachu2000 Posted December 31, 2010 Share Posted December 31, 2010 Echo your query string to be sure it holds the values you'd expect it to hold. Quote Link to comment https://forums.phpfreaks.com/topic/223059-mysql_fetch_array/#findComment-1153262 Share on other sites More sharing options...
Marsha Posted December 31, 2010 Author Share Posted December 31, 2010 So like this? echo 'result = mysql_query("SELECT username FROM data WHERE postid=$postid")'; Quote Link to comment https://forums.phpfreaks.com/topic/223059-mysql_fetch_array/#findComment-1153264 Share on other sites More sharing options...
Pikachu2000 Posted December 31, 2010 Share Posted December 31, 2010 No. Remove the query string from the query execution, and store it in a variable. Then use the variable when executing the query. Doing so makes debugging and error handling much easier. $query = "SELECT username FROM data WHERE postid=$postid"; mysql_query($query); echo $query; Quote Link to comment https://forums.phpfreaks.com/topic/223059-mysql_fetch_array/#findComment-1153266 Share on other sites More sharing options...
Marsha Posted December 31, 2010 Author Share Posted December 31, 2010 Oh I got it now, Thanks very much. Problem was one of the links I was using was not putting a POST into the URL, so it was not retrieving it using GET. Thanks very much for your help. Really helped! Quote Link to comment https://forums.phpfreaks.com/topic/223059-mysql_fetch_array/#findComment-1153269 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.