i'm creating a search page for my website i use this code:
<?php
if (preg_match('/^[a-zA-Z0-9]/', $_GET['search'])) {
$string = $_GET['search'];
}
$result = "SELECT * FROM posts WHERE titel LIKE '$string' OR post LIKE '$string' OR post_full LIKE '$string' ";
$num_rows = mysql_num_rows($result);
if($num_rows > 0){
while($row = mysql_fetch_array($result)){
echo $row['titel'].'<br />';
}
}else {
echo "no posts found";
}
but i get this error:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in D:\wamp\www\blog\search.php on line 38
no posts found
any1 any idea what i'm doing wrong?
thx