Hello I have two files index.php and search.php and I want to enter the string in index.php the search to be preocesed by search.php and the result to be shown in the same window index.php.




<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
      <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
      <title>MAX Group</title>
      <link rel="STYLESHEET" type="text/css" href="style/cautare.css" />
      <script type='text/javascript' src='scripts/gen_validatorv31.js'></script>

<div class="container">
    <div class="header">
        <div class="header_logo">
            <a href="images/firma2.png"><img src="images/firma2.png" alt="Piese Auto Import" name="Piese Auto Import" width="276" height="128" id="Insert_logo" style="background: #8090AB; display:block;" /></a> 
        <div id='fg_membersite_content'>
            Bine ai revenit <?= $fgmembersite->UserFullName(); ?>!

            <p><a class="membersite" href='change-pwd.php'>Schimba parola</a></p>

            <p><a class="membersite" href='logout.php'>Iesire</a></p>
                    <div id="menunav">
                            <li><a href="http://www.games-area.ro/piese/cautare.php" title="Cautare piese"><span>Cauta Piese</span></a></li>
                            <li><a href="http://www.games-area.ro/piese/facturi.php" title="Facturi"><span>Facturi</span></a></li>
                            <li><a href="http://www.games-area.ro/piese/istoric.php" title="Istoric comenzi"><span>Istoric comenzi</span></a></li>    
                            <li><a href="http://www.games-area.ro/piese/logout.php" title="Iesire"><span>Iesire</span></a></li>
                            <li><a href="http://www.games-area.ro/piese/contact.php" title="Contacteaza-ne"><span>Contact</span></a></li>
  <!-- end .header --></div>

  <div class="sidebar1">

<div class="content">
    <div class="cautare">
<form name="form" action="search3.php" method="get">
  <input type="text" name="q" />
  <input type="submit" name="Submit" value="Search" />

  <p>Pentru a cauta un reper va rugam introduceti in caseta de mai sus codul, codul original, codul echivalent sau denumirea.    </p>
  <p>Pentru facilita cautare puteti introduce parti din coduri sau denumire. </p>
  <p>Partile de coduri sau denumire pe care nu le cunoasteti le puteti inlocui cu ..</p>
  <p> <strong>Exemplu:</strong></p>
  <p>» <strong>2429</strong> - afiseaza toate reperele la care unul din cele 4 campuri incepe cu 2429. </p>
<p>» <strong>..bujie</strong> - afiseaza toate reperele care contin in unul din cele 4 campuri cuvantul bujie. </p>
  <p>» <strong>..24..36</strong> - afiseaza toate reperele la care unul din cele 4 campuri contine 24 si 36. </p>
  <div class="sidebar2">

    if($_REQUEST['command']=='delete' && $_REQUEST['pid']>0){
    else if($_REQUEST['command']=='clear'){
    else if($_REQUEST['command']=='update'){
            if($q>0 && $q<=999){
                $msg='Some proudcts not updated!, quantity must be a number between 1 and 999';

<script language="javascript">
    function del(pid){
        if(confirm('Do you really mean to delete this item')){
    function clear_cart(){
        if(confirm('This will empty your shopping cart, continue?')){
    function update_cart(){


<form name="form1" method="post">
<input type="hidden" name="pid" />
<input type="hidden" name="command" />
    <div style="margin:0px auto;" >
        <div style="padding-bottom:10px">
            <p>Your Shopping Cart</p>
            <table border="0" cellpadding="5px" cellspacing="1px" style="font-family:Verdana, Geneva, sans-serif; font-size:11px; background-color:#E1E1E1" width="100%">
                echo '<tr bgcolor="#FFFFFF" style="font-weight:bold"><td>Serial</td><td>Name</td><td>Price</td><td>Qty</td><td>Amount</td><td>Options</td></tr>';
                    if($q==0) continue;
                    <tr bgcolor="#FFFFFF"><td><?=$i+1?></td><td><?=$pname?></td>
                    <td>$ <?=get_price($pid)?></td>
                    <td><input type="text" name="product<?=$pid?>" value="<?=$q?>" maxlength="3" size="2" /></td>                    
                    <td>$ <?=get_price($pid)*$q?></td>
                    <td><a href="javascript:del(<?=$pid?>)">Remove</a></td></tr>
                <tr><td><b>Order Total: $<?=get_order_total()?></b></td><td colspan="5" align="right"><input type="button" value="Clear Cart" onclick="clear_cart()"><input type="button" value="Update Cart" onclick="update_cart()"><input type="button" value="Place Order" onclick="window.location='billing.php'"></td></tr>
                echo "<tr bgColor='#FFFFFF'><td>There are no items in your shopping cart!</td>";
  <div class="footer">
    <p>Copyright © 2010 - 2012 MAX Group. Toate drepturile rezervate</p>
    <!-- end .footer --></div>
  <!-- end .container --></div>

and this is the search.php


  // Get the search variable from URL

  $var = @$_GET['q'] ;
  $trimmed = trim($var); //trim whitespace from the stored variable

// rows to return

// check for an empty string and display a message.
if ($trimmed == " ")
  echo "<p>Please enter a search...</p>";

// check for a search parameter
if (!isset($var))
  echo "<p>We dont seem to have a search parameter!</p>";

//connect to your database ** EDIT REQUIRED HERE **
@mysql_connect("localhost","piese","test"); //(host, username, password)

//specify database ** EDIT REQUIRED HERE **
@mysql_select_db("piese") or die("Unable to select database"); //select which database we're using

// Build SQL Query  
$query = "select * from the_table where 1st_field like \"%$trimmed%\"  
  order by 1st_field"; // EDIT HERE and specify your table and field names for the SQL query


// If we have no results, offer a google search as an alternative

if ($numrows == 0)
  echo "<h4>Results</h4>";
  echo "<p>Sorry, your search: &quot;" . $trimmed . "&quot; returned zero results</p>";

// google
 echo "<p><a href=\"http://www.google.com/search?q=" 
  . $trimmed . "\" target=\"_blank\" title=\"Look up 
  " . $trimmed . " on Google\">Click here</a> to try the 
  search on google</p>";

// next determine if s has been passed to script, if not use 0
  if (empty($s)) {

// get results
  $query .= " limit $s,$limit";
  $result = mysql_query($query) or die("Couldn't execute query");

// display what the person searched for
echo "<p>You searched for: &quot;" . $var . "&quot;</p>";

// begin to show results set
echo "Results";
$count = 1 + $s ;

// now you can display the results returned
  while ($row= mysql_fetch_array($result)) {
  $title = $row["1st_field"];

  echo "$count.)&nbsp;$title" ;
  $count++ ;

$currPage = (($s/$limit) + 1);

//break before paging
  echo "<br />";

  // next we need to do the links to other results
  if ($s>=1) { // bypass PREV link if s is 0
  print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt; 
  Prev 10</a>&nbsp&nbsp;";

// calculate number of pages needing links

// $pages now contains int of pages needed unless there is a remainder from division

  if ($numrows%$limit) {
  // has remainder so add one page

// check to see if last page
  if (!((($s+$limit)/$limit)==$pages) && $pages!=1) {

  // not last page so give NEXT link

  echo "&nbsp;<a href=\"$PHP_SELF?s=$news&q=$var\">Next 10 &gt;&gt;</a>";

$a = $s + ($limit) ;
  if ($a > $numrows) { $a = $numrows ; }
  $b = $s + 1 ;
  echo "<p>Showing results $b to $a of $numrows</p>";


Best way to do this would be to use AJAX. Have an empty DIV for your results on index.php and send the POST data via AJAX to search.php. Than take the results from search.php and add them to the empty results DIV. You would also need to change your pagination links to work as AJAX requests to search.php as well.