0

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());
?>

Edited by bashaash: n/a

2
Contributors
7
Replies
9
Views
5 Years
Discussion Span
Last Post by diafol
0

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().

0

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

0

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.

0

Thanks Ardav the problem is line 40

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

  ?>

Edited by mike_2000_17: Fixed formatting

0

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!

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.