I need help with PHP & MySQL please.

Discussion in 'PHP' started by uploadman1, May 16, 2009.

  1. #1
    Hi, Guys i'm still new with PHP & MySQL and still learning, and now i need help to fix some errors on my website,


    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/content/d/a/v/davidau/html/CatalogList.php on line 6


    Line 6 :

    while($row=mysql_fetch_array($result_catalog))

    Please tell me what is wrong with it and help me to fix it.

    I hope you guys can help me to figure this out.
    thanks in advance.

    Best regards'
    -Me :eek:

    <?php
    	$sq_catalog="Select * from sy_Catalog";
    	$result_catalog = mysql_query($sq_catalog);
    	$count=0;
    	$perRow=12;
    	while($row=mysql_fetch_array($result_catalog))
    	{
    		if(mysql_num_rows($result_catalog)>0)
    		{
    			if ($count<=$perRow)
    			{
    				$catalog = $row["Catalog"];
    				if ($catalog =='Home Decor')
    				{
    				echo "<a class='AMenu' href=index.html>" . $catalog. "</a>&nbsp;&nbsp;<font class='hLine'>|</font>&nbsp;&nbsp; ";					
    				}
    				else if ($catalog =='Zippers')
    				{
    				echo "<a class='AMenu' href=pacific_zipper.php>" . $catalog. "</a>&nbsp;&nbsp;<font class='hLine'>|</font>&nbsp;&nbsp; ";					
    				}
    				else
    				echo "<a class='AMenu' href=ProductList.php?value=" . $catalog . "&cvalue=All>" . $catalog . "</a>&nbsp;&nbsp;<font class='hLine'>|</font>&nbsp;&nbsp; ";
    				$count++;
    			}
    			if ($count==$perRow)
    			{
    				echo "<br>";
    				$count=0;
    			}
    		}
    		else echo "Record not Found!!!";
    		}
    	
    ?>
    
    PHP:
     
    uploadman1, May 16, 2009 IP
  2. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #2
    Try;
    $result_catalog = mysql_query($sq_catalog) or die(mysql_error());
    PHP:
     
    Sky AK47, May 16, 2009 IP
  3. uploadman1

    uploadman1 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    it says "No Database Selected"
     
    uploadman1, May 16, 2009 IP
  4. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #4
    Uh...how can you have no problems connecting in your previous posted code while there's no connection setup.
    And also if you didn't understood, I meant you to replace
    $result_catalog = mysql_query($sq_catalog);
    with
    $result_catalog = mysql_query($sq_catalog) or die(mysql_error());
     
    Sky AK47, May 16, 2009 IP
  5. uploadman1

    uploadman1 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    i did what you've told me sir and that's what i got.
     
    uploadman1, May 16, 2009 IP
  6. uploadman1

    uploadman1 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    maybe the server is offline?
     
    uploadman1, May 16, 2009 IP
  7. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #7
    That would give a different error.
    Is this page included somewhere?
    Connecting and selecting a MySQL Database goes as;
    //Connecting to serve: server location, username, password
    mysql_connect("localhost","username","password");
    //Selecting database: database name
    mysql_select_db("my_database");
    PHP:
     
    Sky AK47, May 16, 2009 IP
  8. uploadman1

    uploadman1 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
       <?php
      $passwd = 'xxxxx';
      $host = 'xxxx.xxxxx.net'; 
      $user = 'xxxxxxx';
      $link = mysql_connect("$host", "$user", "$passwd") or die("Could not connect");
      mysql_select_db($link );
    ?>
    PHP:
     
    uploadman1, May 16, 2009 IP
  9. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #9
    Ah, I see, you missed the database name!
    mysql_select_db("DATABASE NAME", $link);
    PHP:
     
    Sky AK47, May 16, 2009 IP
  10. uploadman1

    uploadman1 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    AWESOME!!! Thank you so much, mate!!!!

    I hope i can learn more from you, next time.

    Thanks thanks thanks!
     
    uploadman1, May 16, 2009 IP
  11. Sky AK47

    Sky AK47 Member

    Messages:
    298
    Likes Received:
    8
    Best Answers:
    1
    Trophy Points:
    45
    #11
    No problem, I like to help others out :)
     
    Sky AK47, May 17, 2009 IP