I am trying to append the code to display the results of the database by including a link, I got the link to work, but it will not display the results when clicked. Below is the code, If you can help me that would be great! Thanks

<?php
//if we got something through $_POST
if (isset($_POST['search'])) {
    // here you would normally include some database connection
    include('db.php');
    $db = new db();
    // never trust what user wrote! We must ALWAYS sanitize user input
    $word = mysql_real_escape_string($_POST['search']);
    // build your search query to the database
    $sql = "SELECT Customer_Name, ID FROM Client_Computer_Info WHERE Customer_Name LIKE '%" . $word . "%' ORDER BY ID LIMIT 10";
    // get results
    $row = $db->select_list($sql);
    if(count($row)) {
        $end_result = '';
        foreach($row as $r) {
            $result         = "\n\t<li><a href=\"search.php?ID={$r['ID']}\">{$r['Customer_Name']}</a></li>";
            // we will use this to bold the search word in result
            $bold           = '<span class="found">' . $word . '</span>';
            $end_result     .= '<li>' . str_ireplace($word, $bold, $result) . '</li>';
        }
        echo $end_result;
    } else {
        echo "<p>Sorry no results for $word</p>";
        }
    }elseif(isset($_GET['ID'])){
    $id = intval($_GET['ID']);
    $query = "SELECT Customer_Name, Computer_Type, Computer_Make, Computer_Model, Serial_Number, Product_Number, OS, `Key` FROM Client_Computer_Info WHERE ID = $id LIMIT 1";
    $n = mysql_query($query);
    echo mysql_error();
    if(mysql_num_rows($n) == 1){
    $d = mysql_fetch_array($n);
    $result  .=     "
    \n<p>Name: {$n['Customer_Name']}</p>
    \n<p>Computer Type: {$n['Computer_Type']}</p>
    \n<p>Computer Make: {$n['Computer_Make']}</p>
    \n<p>Computer Model: {$n['Computer_Model']}</p>
    \n<p>Serial Number: {$n['Serial_Number']}</p>
    \n<p>Product Number: {$n['Product_Number']}</p>
    \n<p>OS: {$n['OS']}</p>
    \n<p>Key: {$n['Key']}</p>";
    }else{
    $result  = "<p>Sorry the ID supplied for the customer does not exist.</p>";
    }
    }
?>

Recommended Answers

All 2 Replies

Lines 25 Down will not display the results. Yes i got the code from there. I am wanting it to do more now. making it a bit more powerful.

ANy ideas on what might be the cause. I have looked it over and over and change a few things but to no avail. it is still blank.

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.