KittyKate Posted July 26, 2006 Share Posted July 26, 2006 I'm getting the warning:Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resourcefrom the following code and don't know why. According the MySQL Query Browser the query works, so what is up with the instruction? I essentially grabbed the code right from: http://ca.php.net/manual/en/function.mysql-query.php[code]<?php$query = sprintf("SELECT Keyword FROM SFM_Project_Keywords WHERE PI_Word = %i AND Code = '%s'", $pi, $_GET['code']);$result = mysql_query($query); $keywords = ""; while ($row = mysql_fetch_assoc($result)) { $keywords .= $row['Keyword'] . " :: ";}?>[/code] Link to comment https://forums.phpfreaks.com/topic/15750-warning-mysql_fetch_assoc-not-a-valid-mysql-result/ Share on other sites More sharing options...
ryanlwh Posted July 26, 2006 Share Posted July 26, 2006 one trick to debug queries: mysql_error().[code]$result = mysql_query($query) or die(mysql_error());[/code]another good way is to echo the query to screen, so you see exactly what went wrong. sometimes manually typing a query into mysql browser and the actual query generated from php are different.From what I see here you are probably missing the quotes around %i Link to comment https://forums.phpfreaks.com/topic/15750-warning-mysql_fetch_assoc-not-a-valid-mysql-result/#findComment-64385 Share on other sites More sharing options...
scheols Posted July 27, 2006 Share Posted July 27, 2006 [code=php:0]<?php$query = sprintf("SELECT Keyword FROM SFM_Project_Keywords WHERE PI_Word = %i AND Code = '%s'", $pi, $_GET['code']);$result = mysql_query($query); $keywords = ""; while ($row = mysql_fetch_array($result)) { $keywords .= $row['Keyword'] . " :: ";}?>[/code] try that Link to comment https://forums.phpfreaks.com/topic/15750-warning-mysql_fetch_assoc-not-a-valid-mysql-result/#findComment-64468 Share on other sites More sharing options...
KittyKate Posted July 27, 2006 Author Share Posted July 27, 2006 Turns out fprints() didn't like the %i. Switching it up to a %s didn't work, but putting $pi right into the string fixed the error. Since the value of $pi is set within the script I'm not worried about SQL injection attacks. The query string now looks like:[code]$query = sprintf("SELECT Keyword FROM SFM_Project_Keywords WHERE PI_Word = $pi AND Code = '%s'", mysql_real_escape_string($_GET['code']));[/code]Thanks for the help! Link to comment https://forums.phpfreaks.com/topic/15750-warning-mysql_fetch_assoc-not-a-valid-mysql-result/#findComment-64670 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.