Jump to content

Recommended Posts

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 17

any 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 appricated

thanks
djcontact
Link to comment
https://forums.phpfreaks.com/topic/13243-mysql_fetch_array/
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/13243-mysql_fetch_array/#findComment-50984
Share on other sites

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 again
djcontact
Link to comment
https://forums.phpfreaks.com/topic/13243-mysql_fetch_array/#findComment-50999
Share on other sites

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
Link to comment
https://forums.phpfreaks.com/topic/13243-mysql_fetch_array/#findComment-51000
Share on other sites

this is what i have on my connection.php
[code]
#database access info
define ('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]
Link to comment
https://forums.phpfreaks.com/topic/13243-mysql_fetch_array/#findComment-51009
Share on other sites

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]
Link to comment
https://forums.phpfreaks.com/topic/13243-mysql_fetch_array/#findComment-51011
Share on other sites

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 help
thanks
Link to comment
https://forums.phpfreaks.com/topic/13243-mysql_fetch_array/#findComment-51019
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.