djcontact Posted June 29, 2006 Share Posted June 29, 2006 ok some im getting these error:[b]Warning:[/b] mysql_fetch_array(): 20 is not a valid MySQL result resource in [b]/home/nelsona/public_html/index.php[/b] on line 9[b]Warning:[/b] mysql_free_result(): 20 is not a valid MySQL result resource in [b]/home/nelsona/public_html/index.php[/b] on line 17any idea why im perhaps getting this error...i first did this site on my server and had no problems,then transfered it over to the clients server and now im getting this error.any help would be appricatedthanksdjcontact Quote Link to comment https://forums.phpfreaks.com/topic/13243-mysql_fetch_array/ Share on other sites More sharing options...
wildteen88 Posted June 29, 2006 Share Posted June 29, 2006 You usually get this error message when you have an error in your sql query. Please read [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95376\" target=\"_blank\"]this thread[/a]. Also seardch the forum too as this question has been answered many times over Quote Link to comment https://forums.phpfreaks.com/topic/13243-mysql_fetch_array/#findComment-50984 Share on other sites More sharing options...
djcontact Posted June 29, 2006 Author Share Posted June 29, 2006 so i read that thread you suggested [a href=\"http://www.phpfreaks.com/forums/index.php?showtopic=95376\" target=\"_blank\"]Invalid Resource, MySQL[/a] and it doesnt really answer my question...either that or im just not understanding it...i also went ahead and did a search for mysql_fetch_array and i did get a hand full of search results but nothing that i can relate too...well with the amount of php knowledege that i know which is not much, i would love to get some assistants on this.thanks againdjcontact Quote Link to comment https://forums.phpfreaks.com/topic/13243-mysql_fetch_array/#findComment-50999 Share on other sites More sharing options...
thepip3r Posted June 29, 2006 Share Posted June 29, 2006 and how are your mysql queries set up for error checking?? here is a simple and reliable way to do error trapping with MySQL:[code]$result = mysql_query("SELECT * FROM TABLE WHERE blah='$blah'") or die("MySQL Query failed: ".mysql_error());[/code]the mysql_error() function will allow you to get the error reported by MySQL Quote Link to comment https://forums.phpfreaks.com/topic/13243-mysql_fetch_array/#findComment-51000 Share on other sites More sharing options...
djcontact Posted June 29, 2006 Author Share Posted June 29, 2006 this is what i have on my connection.php[code]#database access infodefine ('DB_USER', 'myuser');define ('DB_PASS', 'mypass');define ('DB_HOST', 'localhost');define ('DB_NAME', 'mydbname');#database connection$dbc = mysql_connect (DB_HOST, DB_USER, DB_PASS) OR die ('Could not connect to mysql: ' .mysql_error() );mysql_select_db (DB_NAME) OR die ('Could not select database: ' .mysql_error() );[/code]and this is my index.php[code]include ('_include/connect.php');//make query$query = "SELECT * FROM layout";//run the query$result = @mysql_query ($query);if ($result) { //fetch while ($row = mysql_fetch_array($result, MYSQL_NUM)) { if($row[0] == 1) { include ('layout_01.php'); } if($row[0] == 2) { include ('layout_02.php'); } } mysql_free_result ($result); //free up the resources} else { //if it did not run ok echo '<p>The content could not be displayed due to system error!</p>';}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13243-mysql_fetch_array/#findComment-51009 Share on other sites More sharing options...
thepip3r Posted June 29, 2006 Share Posted June 29, 2006 so you need to add some error checking for your MySQL statement like i already posted. change your code to look like this:[code]include ('_include/connect.php');//make query$query = "SELECT * FROM layout";//run the query$result = @mysql_query ($query) or die("MySQL query failed: ".mysql_error());if ($result) { //fetch while ($row = mysql_fetch_array($result, MYSQL_NUM)) { if($row[0] == 1) { include ('layout_01.php'); } if($row[0] == 2) { include ('layout_02.php'); } } mysql_free_result ($result); //free up the resources} else { //if it did not run ok echo '<p>The content could not be displayed due to system error!</p>';}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13243-mysql_fetch_array/#findComment-51011 Share on other sites More sharing options...
djcontact Posted June 29, 2006 Author Share Posted June 29, 2006 ok so i added the error checking for the mysql statement but im still getting the same error,[b]Warning:[/b] mysql_fetch_array(): 20 is not a valid MySQL result resource in [b]/home/nelsona/public_html/index.php[/b] on line [b]9[/b][b]Warning:[/b] mysql_free_result(): 20 is not a valid MySQL result resource in [b]/home/nelsona/public_html/index.php[/b] on line [b]17[/b]i really appricate the helpthanks Quote Link to comment https://forums.phpfreaks.com/topic/13243-mysql_fetch_array/#findComment-51019 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.