SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2003
    Location
    NJ
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mySql query resource problem in PHP page

    Hello,

    I am getting a strange error when trying to run a query for my site. The database connection info, table, and fields are all correct and I have a sample row of data in the table.

    However, I get this error everytime I load the page:

    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pinemind/public_html/newsClass.php on line 31

    Here is the php code I use to access the db:

    Code:
    function displayNews($numupdates = 5)
    {
    
    $max_news = $numupdates;
    $host = "localhost";
    $user = "pinemind_admin";
    $pw = "**";
    
    
    global $d;
    	
    $d = mysql_pconnect($host,$user,$pw);
    
    mysql_select_db("pinemind_pinemind",$d);
    
    $query = "SELECT headline,updatetext,DATE_FORMAT(postdate, '%Y-%m-%d') as date FROM news ORDER BY postdate DESC LIMIT $max_news";
    
    $result = mysql_query($query);
    
    while ($row = mysql_fetch_array($result)) 
    {
    	$date = $row['date'];        
    	$headline = htmlentities($row['headline']);
    	$updatetext = nl2br(strip_tags ($row['updatetext'], '<a><b><i><u>'));
    	
    	echo "<div id=\"news\">\n";
    	echo "<h5>$headline&nbsp;:$date</h5>\n";
    	echo "<p>$updatetext</p>\n";
    	echo "<p class=\"sig\"><a class=\"sig\" href=\"mailto:jbbarrens@pinemind.com\">Justin</a></p>\n";
    	echo "</div>\n";
    }
    
    }

    Here is a link to the site

    Don't mind the layout . . . a thread I posted in the CSS forum is waiting to be answered, hopefully . ..

    Thanks in advance for any insight!

    Justin

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,580
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Do you have phpMyAdmin? If so, try your query in the SQL tab there (fill in your variable with some likely value) and see if it gives you an error there. If so, it probably tells you why, if not then it is your script.

    If the mysql_query() fails, then the fetch array will not have a $result to use and that will cause your error.

    Right now your site is giving 'too many connections' errors all over.

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2003
    Location
    NJ
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    S

    I ran the query in phpMyadmin and it worked fine. It returned the correct data. I even tried taking off the limit and it still won't work in the page. Does anyone have any idea what could be going wrong still?

    Justin

  4. #4
    SitePoint Enthusiast
    Join Date
    Jul 2003
    Location
    NJ
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, it has somehow fixed itself. I found it by including a debug message that it really wasn't finding the database. However, I just retyped the correct name of the database that I had in there before, and it works magically . . . go figure.

    Sorry no one learned from this because I have no idea why it works now. I guess we can learn the time honored lesson that compiler generated error messages are pretty worthless . . .hehe.

    Peace,
    Justin


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •