Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8067945
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:29:59+00:00 2026-06-05T12:29:59+00:00

I have picked up this code from a tutorial and have edited it make

  • 0

I have picked up this code from a tutorial and have edited it make it suitable for my needs.

<?php
//if we got something through $_POST
if (isset($_POST['search'])) {
    // here you would normally include some database connection
    include('config2.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 name FROM $tbl_name WHERE name LIKE '%" . $word . "%'";
    // get results
    $row = $db->select_list($sql);
    if(count($row)) {
        $end_result = '';
        foreach($row as $r) {
            $result         = $r['title'];
            // 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 '<li>No results found</li>';
    }
}
?>

I am getting this error when I run the code:

Fatal error: Class 'db' not found in /home/peltdyou/public_html/do_search.php on line 6

I am very new to PHP so could anyone shed some light onto my problem..

UPDATE:

<?php   

    class db {

    function __construct()
    {
        global $dbh;
        if (!is_null($dbh)) return;
        $dbh = mysql_pconnect(DB_HOST, DB_USER, DB_PASSWORD);
        mysql_select_db(DB_NAME);
        mysql_query('SET NAMES utf8');
    }

    function select_list($query)
    {
        $q = mysql_query($query);
        if (!$q) return null;
        $ret = array();
        while ($row = mysql_fetch_array($q, MYSQL_ASSOC)) {
            array_push($ret, $row);
        }
        mysql_free_result($q);
        return $ret;
    }   
 } 
?>

This is the db.php code.. I thought by replacing this with my own config2.php file I could get it to connect to my database.. Obviously not

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:30:02+00:00Added an answer on June 5, 2026 at 12:30 pm

    I think I found the sample script you used, and in it, they say:

    // here you would normally include some database connection
    include('db.php');
    

    In the example, the db.php is not described, assuming that you have such a database file that you would use. A little further searching, I found this database class, which they call “database.php”, but you could easily use it for the code that you’re trying work with.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have picked up this AJAX code from multiple tutorials, but the problem is,
I have picked up this code(DragandDrop.jsp) from this page :: http://jsfiddle.net/petersendidit/S4QgX/ I am getting
I have this bit of code that get the image i have picked from
While learning c#, I have picked up the implication from reading other people's code
I have this code (snippet) from a .h file: #import <UIKit/UIKit.h> #import ILView.h /**
I have the following code -> something like Select case using LINQ - This
I have ported some code from Mingw which i wrote using code::blocks, to visual
I'm following this [slightly old tutorial for 2d java games here][1]. I have a
I have some working Javascript code that generates an RDF/XML document using variables picked
I get this code snippet from some where else. According to the webmaster, the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.