Hi to all I am having this problem can anyone help me to solv this problem pls
here is the code.

first problem

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /hermes/web07/b2501/mydomain.com/htdocs/media.php on line 40

media.php code

<?php
   

      $connection = mysql_connect('localhost','test','test');

      if (!$connection)

      {

      die ('error connecting to database server'.mysql_error());

      }

       

      mysql_select_db('hiiraan', $connection);

      
      $result = mysql_query("SELECT * FROM mp3s WHERE id = '{$_GET['id']}'") or die(mysql_error());

     if(mysql_num_rows($result))

      {

      while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {

          $mp3s = $row['filepath'];
	  $title = $row['title'];
	  $author = $row['author'];
	  $count = $row['hitcounter'];	

      //echo $mp3s;

      }

      }
          $count = $count + 1;
	  	  
	  $result=mysql_query("Update mp3s set hitcounter='$count' where id='{$_GET['id']}'") or die(mysql_error());
	  if (mysql_num_rows($result > 0))  // here is line 40 
		{
		  echo "records updated";
		}

      ?>

here is the base.php code

<?php
@session_start();
$dbhost = "domain.com"; // this will ususally be 'localhost', but can sometimes differ
$dbname = "test"; // the name of the database that you are going to use for this project
$dbuser = "test"; // the username that you created, or were given, to access your database
$dbpass = "test"; // the password that you created, or were given, to access your database
mysql_connect($dbhost, $dbuser, $dbpass) or die("MySQL Error: " . mysql_error());
mysql_select_db($dbname) or die("MySQL Error: " . mysql_error());
?>

Recommended Answers

All 7 Replies

Member Avatar for diafol

There is an error in the query probably due to $_GET not existing. You need to check for its existence first and also clean it with intval() or mysql_real_escape_string().

Thanks Ardav for your help but my code was working fine yesterday I got this error today I don't know what happened to my code can you fix my problem? sir thanks again

Member Avatar for diafol

I'm not sure if I can, but here's a go:

if(isset($_GET['id'])){
  $int = intval($_GET['id']); //I assume this is supposed to be an integer
  $result = mysql_query("SELECT * FROM mp3s WHERE id = $int") or die(mysql_error());
  if(mysql_num_rows($result) > 0){
     while($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
          $mp3s = $row['filepath'];
	  $title = $row['title'];
	  $author = $row['author'];
	  $count = $row['hitcounter'];
         //echo your mp3 in a format you need	
     }
  } 
}

//update query ???

If it doesn't work, try pasting a similar query directly into your phpmyadmin SQL box and see what happens.

Thanks Ardav the problem is line 40

    if (mysql_num_rows($result > 0))  // here is line 40 
    {
      echo "records updated";
    }

  ?>
Member Avatar for diafol

Look again:

if(mysql_num_rows($result) > 0){

I had to edit it - put the bracket in the wrong place - you were too quick for me!

I am still getting same problem sorry

Member Avatar for diafol

you've done the phpmyadmin thing?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.