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.

index.php

<?PHP
require_once("includes/membersite_config.php");

if(!$fgmembersite->CheckLogin())
{
    $fgmembersite->RedirectToURL("login.php");
    exit;
}

?>
<!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">
<head>
      <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>
</head>

<body>
<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>
        <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>
                    <div id="menunav">
                        <ul>
                            <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>
                        </ul> 
                    </div>
  <!-- end .header --></div>

  <div class="sidebar1">

</div>
<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" />
</form>
    </div>



  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <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>
  <div class="sidebar2">
    <?php
    include("includes/db.php");
    include("includes/functions.php");

    if($_REQUEST['command']=='delete' && $_REQUEST['pid']>0){
        remove_product($_REQUEST['pid']);
    }
    else if($_REQUEST['command']=='clear'){
        unset($_SESSION['cart']);
    }
    else if($_REQUEST['command']=='update'){
        $max=count($_SESSION['cart']);
        for($i=0;$i<$max;$i++){
            $pid=$_SESSION['cart'][$i]['productid'];
            $q=intval($_REQUEST['product'.$pid]);
            if($q>0 && $q<=999){
                $_SESSION['cart'][$i]['qty']=$q;
            }
            else{
                $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')){
            document.form1.pid.value=pid;
            document.form1.command.value='delete';
            document.form1.submit();
        }
    }
    function clear_cart(){
        if(confirm('This will empty your shopping cart, continue?')){
            document.form1.command.value='clear';
            document.form1.submit();
        }
    }
    function update_cart(){
        document.form1.command.value='update';
        document.form1.submit();
    }


</script>

<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>
        </div>
            <table border="0" cellpadding="5px" cellspacing="1px" style="font-family:Verdana, Geneva, sans-serif; font-size:11px; background-color:#E1E1E1" width="100%">
        <?
            if(is_array($_SESSION['cart'])){
                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>';
                $max=count($_SESSION['cart']);
                for($i=0;$i<$max;$i++){
                    $pid=$_SESSION['cart'][$i]['productid'];
                    $q=$_SESSION['cart'][$i]['qty'];
                    $pname=get_product_name($pid);
                    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>
            <?
            }
            else{
                echo "<tr bgColor='#FFFFFF'><td>There are no items in your shopping cart!</td>";
            }
        ?>
        </table>
    </div>
</form>
</div>
  <div class="footer">
    <p>Copyright © 2010 - 2012 MAX Group. Toate drepturile rezervate</p>
    <!-- end .footer --></div>
  <!-- end .container --></div>
</body>
</html>

and this is the search.php

<?php

  // Get the search variable from URL

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

// rows to return
$limit=10; 

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

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

//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

 $numresults=mysql_query($query);
 $numrows=mysql_num_rows($numresults);

// 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)) {
  $s=0;
  }

// 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
  $prevs=($s-$limit);
  print "&nbsp;<a href=\"$PHP_SELF?s=$prevs&q=$var\">&lt;&lt; 
  Prev 10</a>&nbsp&nbsp;";
  }

// calculate number of pages needing links
  $pages=intval($numrows/$limit);

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

  if ($numrows%$limit) {
  // has remainder so add one page
  $pages++;
  }

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

  // not last page so give NEXT link
  $news=$s+$limit;

  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.

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.