Showing Results as ... could not find

<?php
mysql_connect("localhost","root","") or die ("could not connect");
mysql_select_db("search_test") or die ("could not find db!");

//collect
if(isset($_POST['search'])){
	$searchq = $_POST['search'];
	$searchq = preg_replace("#[^0-9a-z]#i","",$searchq); 

	$query = mysql_query("SELECT * FROM 'members' WHERE firstname LIKE '%$searchq%' OR lastname LIKE '%$searchq%'") or die ("could not search!");
	$count = mysql_num_rows($query);
 if ($count == 1 ) {
  $output = 'There was no search results!';
 	}else{
		while($row = mysql_fetch_array ($query)) {
			$fname = $row ['firstname'];
			$lname = $row ['lastname'];
			$id = $row ['ID'];
			
			$output .='<div>'.$fname.' '.$lname.' </div>';
			}
		}
}
print $output = ""; ?>

<html>
<head>
<meta http-equiv="content-Type" content="txt/html; charset=utf=8" />
<title>Search</title>
</head>

<body>

<form action="index.php" method="post">
	<input type="test" name="search" placeholder="Search for members...">
	<input type="submit" value="GO" /> 
    </form>
    

    
</body>
</html>

Can you tell us what your question is?

It would be more help if you put all your code between the sets of ticks rather than just two lines of it.

Thank You verymuch for replay… i am working on php serach tutorials… and i am beginner to this programming… i want to display my database results on website… when i write the above program …

the searching is dying at this string

$query = mysql_query(“SELECT * FROM ‘members’ WHERE firstname LIKE ‘%$searchq%’ OR lastname LIKE ‘%$searchq%’”) or die (“could not search!”);

Hi Divya. Well, the first thing, if you want your scripts to work on your website, is that the mysql_* functions are now virtually dead. You should be using mysqli_* calls or PDO. Unfortunately many tutorials on the web are out-of-date.

Dear sir, suggest me a good tutorial

You can try one of these PDO tutorials

And a recommended book is Simply SQL by Rudy Limeback (who is also a Sitepoint member).

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.