I am creating an internal extension directory using html. How do I connect html to mysql database so as to be able to retrieve the extension number of the person I am looking for.

Dani AI

Generated

is correct that plain HTML cannot talk directly to MySQL. A small server-side layer (PHP, Node, Python, etc.) must accept the search term, run a safe query, and return results which the page then displays. For quick local development on Windows, tools like XAMPP are commonly used; on macOS/Linux look at MAMP/LAMP or containers if you prefer reproducible setups.

Design and security notes you won’t find in the original reply: model a simple table with fields such as employee_id, first_name, last_name, extension, department, location, email. Index the columns you will search (name, extension) so lookups stay fast. Never use the database root account for the web app — create a dedicated DB user with only the privileges it needs (SELECT for a read-only directory). Store credentials outside the web root and use parameterized queries / prepared statements to avoid SQL injection (see PDO or MySQLi prepared-statement docs for examples).

UX and interaction guidance: use a single, forgiving search box that accepts name fragments or extension numbers. Implement typeahead/autocomplete with debounced requests to the server (avoid firing a request on every keystroke). Show compact result cards that include extension, location and department; make keyboard navigation and accessible labels standard; on phones expose a tap-to-call action (tel:). For large datasets add pagination or incremental loading and surface relevance (exact number matches first, then name matches).

High-level implementation flow: create the database and seed it, build a small API endpoint that returns JSON for a search term, call that endpoint via AJAX (or render server-side) and render results with accessible markup. In production restrict access to the internal network or VPN, enable HTTPS, and do not expose admin tools like phpMyAdmin. Troubleshoot by checking server logs, verifying service status (Apache/MySQL), and confirming DB user privileges.

Recommended Answers

All 2 Replies

You cannot use HTML to connect to MySQL, the closest you can get is the PHP (Hypertext Preprocessor). I assume you're running Windows. You would need Apache server for this. I personally would recommend installing XAMPP, which has MySQL and Apache server in it. After all installation, at the end you will be asked whether open "Control Panel", makes sure that the box is checked and the panel will open, start Apache and MySQL servers. After this, go to: C:/xampp/htdocs/ create folder projects, in there, make a file called config.php, open this file with your favourite editor (let it be Notepad++, Brackets, SublimeEditor, Microsoft Notepad) and in there, copy this:

<?php
    $sql_un = "root";   // default: "root";
    $sql_pd = "";       // default: "";
    $sql_db = "";       // you will need to create database and input here it's name
    $sql_conn = mysqli_connect("127.0.0.1", $sql_un, $sql_pd, $sql_db);

    if (!$sql_conn) {
        die("Something didn't work, the file couldn't connect to database!");
    }
    echo "File's request has been successfully sent and answer received.";

?>

If you need further assistance with phpMyAdmin, or Apache server. Feel free to ask.

Thank you! Let me work on it and get back to you

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.