I am trying to develop a seach page to search the customer files that in the database. I want to be able to search and the result display on the same page and i can search for another customer without going to another page.

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script type="text/javascript">

$(function() {

    $(".search_button").click(function() {
        // getting the value that user typed
        var searchString    = $("#search_box").val();
        // forming the queryString
        var data            = 'search='+ searchString;

        // if searchString is not empty
        if(searchString) {
            // ajax call
                type: "POST",
                url: "getdev.php",
                data: data,
                beforeSend: function(html) { // this happens before actual call
               success: function(html){ // this happens after we get results
        return false;

<?php include('header.html.php'); ?>
<div id="content">
    <div id="columnC">
        <h2>Search Customers</h2>

<form method="post" action="getdev.php">
    <input type="text" name="search" id="search_box" class='search_box'/>
    <input type="submit" value="Search" class="search_button" /><br />

      <div id="searchresults">Search results :</div>



so this is php file 
//if we got something through $_POST
if (isset($_POST['search'])) {
    // here you would normally include some database connection
   // $db = new db();
    // never trust what user wrote! We must ALWAYS sanitize user input
    $word = mysql_real_escape_string($_POST['search']);
    $word = htmlentities($word);
    // build your search query to the database
    $q = "SELECT custid, cdate, custName, address1, address2, phone, cellphone, email, equipment, manufacturer, model, serial, imei, notes, priority FROM customer WHERE custid='$word' OR custName like '$word' ORDER BY equipment ASC ";      
$result = @mysqli_query ($dbcon, $q); // Run the query.
if ($result) { // If it ran, display the records.
// Table header.
echo '<table id="result"> <tr>
<th><b>Address </b></th>
<th><b>Phone </b></th>
<th><b>Cellphone </b></th>

    } else {
        echo '<li>No results found</li>';

I am not getting any result on the page at all. Any help or link to an example would be lovely

Hi Ryan,

  • echo the query and check if the final query is correct - you can also try to run the query in phpmyadmin and see if it returns any results.
  • if you don't have access to phpmyadmin, try removing the suppress error operator '@' when you run the query.
  • call mysqli_error() after you run the query, this will give you more details if something went wrong
  • depending on your server settings, you might need to turn on error reporting

    error_reporting(E_ALL); // report all errors
    ini_set('display_errors', 1); // send to output

  • your query is looking for an exact match, use wildcard to search parts of the string: LIKE '%$word%'

Hi Ryan,
In your getdev.php file, I don't see where is the $result to be displayed. In your code, you are only displaying the header

Thank guys for your response, i got it to work you assistance was really appreciated

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.