I was following a tutorial and i copied word by word i don't know why i get the error.
Error >> Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/*****/public_html/download/url/search.php on line 36

<?php
		
		 $results = $_GET['results'];
		 $terms = explode(" ", $results);
		 $query = "SELECT * FROM search WHERE keywords='$term1'";
		 
		 foreach ($terms as $each) {
				$i++;
				if ($i == 1)
					$query .= "keywords LIKE '%$each%' ";
				else 
					$query .= "OR keywords LIKE '%$each%' ";
			}
			
			// connect
			mysql_connect("localhost", "irnm_tutadmin", "731995");
			mysql_select_db("irnm_tutorials");
			
			$query = mysql_query($query);
			$numrows = mysql_num_rows($query);
			if ($numrows > 0) {
			
				while ($row = mysql_fetch_assoc($query)){
					$id = $row['id'];
					$title = $row['title'];
					$description = $row['description'];
					$keywords = $row['keywords'];
					$link = $row['link'];
					
					echo "<h2><a href='$link'>$title</a></h2>
					$description<br /><br />";
				}
			}
			else
				echo "No results found for \"<b>$results</b>\"";
			
			
			// disconnect
			mysql_close();
	
	?>

what is $term1 in your query(line 5)? Where did you define $term1?

Replace your line no 5

$query = "SELECT * FROM search WHERE keywords='$term1'";

with

$query = "SELECT * FROM search WHERE ";

You're putting the result in $query on line 19, which is a bit strange to me. It shouldn't break things, but it's more clear if you rename that variable to $result.

Also always try to habit of mysql_error so once there is something wrong with query your code wont execute further.

$rs=mysql_query($sql) or die( '<br /><strong>Your Query: </strong>'.$sql.'<br /><br /><strong>Error: </strong>'.mysql_error());

There's a problem with your SQL syntax.

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.