1

I have a search box and results, when I click the result and directed to a specific page I want the result to show at the header of directed page with php.

This is the result page:

<?php
$host="localhost";
$user="a";
$pass="a";
$db="pax";
mysql_connect($host,$user,$pass);
mysql_select_db($db);


$button = $_GET['submit'];
$search = $_GET['search'];

if (!$button)
 echo "you didn't submit a keywoard";
else
{
   if (strlen($search)<=2)
       echo " Search term too short";
   else 
   {
       echo " you searched for $search<hr size='1'>";
   }
}
$sql="select * from names where names like '%$search%'";
$query = mysql_query($sql);
while($row=mysql_fetch_array($query)){

echo '<a href=directedpage.php </a>'. "<br>".$row['names'];
}

?>
  • `'$pass="a";` is this a mistake because to me this looks like it'll throw a syntax error – Memor-X Nov 30 '15 at 23:48
  • thanks .. yes this mistake during post writing – mohammad alsharqi Nov 30 '15 at 23:51
  • You really should not be writing code that relies on mysql_ functions anymore. The MySQL extension has been deprecated for years and is about to be dropped in the upcoming PHP7 release. Also see [Why shouldn't I use mysql_* functions in PHP?](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php). – Tristan Dec 01 '15 at 00:01
  • then what is the alternative way . iam newer member in programming – mohammad alsharqi Dec 01 '15 at 00:08

1 Answers1

0

You have a few syntax errors in the HTML that is echoed so I've simplified. The directedpage.php will need to receive the search term and put it in the appropriate place.

Example: From your code-

echo '<a href=directedpage.php?searchTerm='.$search.'>Click Here</a>';

An abbreviated directedpage.php-

echo '<html><head><title>'.$_POST['searchTerm'].'</title></head>';
....

This can be expanded upon sending all sorts of analytical data to the "directedpage.php" using any method you see fit.

Vinny M
  • 762
  • 4
  • 14