Tag: HTML

  • HTML, CSS and PHP

    To create an HTML form that allows users to search data from a “people” database table based on a Registration Number input and display the query results with specified output elements, you would typically use HTML for the form structure and CSS for styling. Here’s how you can set it up:

    HTML (index.html):

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Search people Database</title>
    <link rel="stylesheet" href="styles.css">
    </head>
    <body>
    <div class="container">
    <h2>Search people Database</h2>
    <form action="search.php" method="GET">
    <label for="classNo">Class Number:</label>
    <input type="text" id="classNo" name="classNo" placeholder="Enter class number...">
    <button type="submit">Search</button>
    </form>
    </div>
    </body>
    </html>

    Explanation:

    • This HTML structure includes a simple form with an input field (classNo) and a submit button (Search).
    • The form is set to submit data using the GET method to a PHP script (search.php).
    • The <link> tag includes a CSS file (styles.css) for styling the form and results.
    CSS (styles.css):
    cssCopy code.container {
        max-width: 600px;
        margin: 0 auto;
        padding: 20px;
        background-color: #f2f2f2;
        border: 1px solid #ccc;
        border-radius: 5px;
    }
    
    form {
        display: flex;
        align-items: center;
    }
    
    label, input, button {
        margin: 5px;
    }
    
    button {
        padding: 10px 20px;
        background-color: #4CAF50;
        color: white;
        border: none;
        border-radius: 3px;
        cursor: pointer;
    }
    
    button:hover {
        background-color: #45a049;
    }
    
    Explanation:
    • The CSS file (styles.css) styles the form container (div.container) to center it on the page, provide padding, and a border for visual separation.
    • The form (form) and its elements (label, input, button) are styled with margins, padding, background colors, borders, and hover effects to enhance usability.

    PHP (search.php)

    Assuming you have a PHP script (search.php) that connects to your database and retrieves search results based on the classNo input. Here’s a simplified example:

    phpCopy code<?php
    // Check if classNo is provided
    if (isset($_GET['classNo'])) {
    $classNo = $_GET['classNo'];

    // Perform database query using $classNo
    // Replace with your actual database connection and query logic
    $servername = "localhost";
    $username = "username";
    $password = "password";
    $dbname = "your_database_name";

    // Create connection
    $conn = new mysqli($servername, $username, $password, $dbname);

    // Check connection
    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    }

    // Example query (you should sanitize input to prevent SQL injection)
    $sql = "SELECT FirstName, MidName, Sirname, EnrollmentDate, Email, MobileNumber, ResidentArea, Fellowship, Teacher, timeAvailable
    FROM people
    WHERE classNo = '$classNo'";
    $result = $conn->query($sql);

    // Display results in a form
    if ($result->num_rows > 0) {
    echo "<div class='container'>";
    echo "<h2>Search Results</h2>";
    echo "<form>";
    while($row = $result->fetch_assoc()) {
    echo "<label>First Name:</label> <input type='text' value='" . $row["FirstName"] . "' readonly><br>";
    echo "<label>Middle Name:</label> <input type='text' value='" . $row["MidName"] . "' readonly><br>";
    echo "<label>Surname:</label> <input type='text' value='" . $row["Sirname"] . "' readonly><br>";
    echo "<label>Enrollment Date:</label> <input type='text' value='" . $row["EnrollmentDate"] . "' readonly><br>";
    echo "<label>Email:</label> <input type='text' value='" . $row["Email"] . "' readonly><br>";
    echo "<label>Mobile Number:</label> <input type='text' value='" . $row["MobileNumber"] . "' readonly><br>";
    echo "<label>Resident Area:</label> <input type='text' value='" . $row["ResidentArea"] . "' readonly><br>";
    echo "<label>Fellowship:</label> <input type='text' value='" . $row["Fellowship"] . "' readonly><br>";
    echo "<label>Teacher:</label> <input type='text' value='" . $row["Teacher"] . "' readonly><br>";
    echo "<label>Time Available:</label> <input type='text' value='" . $row["timeAvailable"] . "' readonly><br>";
    }
    echo "</form>";
    echo "</div>";
    } else {
    echo "<div class='container'>";
    echo "<p>No results found for Class Number: $classNo</p>";
    echo "</div>";
    }

    $conn->close();
    } else {
    echo "<div class='container'>";
    echo "<p>No class number provided.</p>";
    echo "</div>";
    }
    ?>

    Explanation:

    • The PHP script (search.php) receives the classNo from the HTML form via $_GET['classNo'].
    • It connects to the database and performs a SQL query (SELECT ... FROM people WHERE classNo = '$classNo') to retrieve data based on the provided classNo.
    • Results are displayed in a styled form using HTML <input> elements set to readonly to prevent editing.

    Notes:

    • Security: Always sanitize and validate user input ($classNo) to prevent SQL injection attacks.
    • Database Connection: Ensure your PHP script (search.php) correctly connects to your database and handles errors appropriately.
    • Styling: Customize the CSS (styles.css) to match your design preferences and ensure usability.

    This example provides a foundational setup for implementing a search functionality in a web application, retrieving data from a database, and displaying it in a styled form. Adjust the PHP SQL query and HTML structure as per your specific database schema and design requirements.


  • HTML

    HTML

    HTML stands for Hyper Text Markup Language. It is the standard markup language for documents designed to be displayed in a web browser.

    It is the language we use to define the content and structure of the web. A markup language is used to format plain text.

    HTML is used alongside other supporting technologies like CSS and JavaScript.

    In HTML, we will not find language constructs found in programming languages like loops and variable declaration. We simply declare elements to represent structures like text, list, image, paragraphs, links etc, to show how they should be displayed on the web.

    HTML is mostly a static language, we therefore uses JavaScript to do what HTML wont do; adding interactivity in the webpage.

    Tags

    HTML uses tags which are keywords enclosed with brackets <>. This tags usually comes in pairs

    HTML tags are usually in pairs for example <p></p> is used to represent opening and closing of a paragraph.

    common tags in HTML includes:

    <!DOCTYPE>

    It indicates the particular version of HTML being used in the document. It helps the web browser understand the version of the HTML used in the document.

    for example <!DOCTYPE HTML PUBLIC “HTML 4.01”> indicates that HTML 4 is being used.

    <!DOCTYPE html> indicates HTML5 is being used.

    <html>

    Used to represent the root of an HTML document that are below the <!DOCTYPE> element.

    It encloses the complete HTML document and mainly comprises of document header and body. You should include the lang attribute inside the <html> tag as in <html lang=”en”> to declare the language used on the web page which is a useful attribute to search engines and browsers.

    <head>

    Contains meta information about the HTML page. The tag holds HTML tags like <title></title> and <links></links>

    <title>

    Specifies a title for the HTML page which generally appears in the title bar of the web browser.

    <body>

    defines the document ‘s body indicates a container for for all visible contents such as paragraphs and images.

    <!– – – >

    It is a comment meaning it contains information that is only visible to programmer but which will not be rendered into the webpage. It allows a web author provides notes and explain what they are doing.

    <Heading Tags>

    They are the start point for a document. They have different sizes, about six levels with highest being <h1> and the lowest <h6>

    h1 means heading 1.

    browser usually add one line before and after heading.

    Paragraph Tag <p>

    It offers a way to structure your text into different paragraphs where each paragraph goes between <p> and </p>.

    line break

    It creates a new line with an element <br /> causing anything after it start on a new line. It does not need opening or closing tags as there is nothing in between it. Please not that there is a space between br and the slash / which when omitted creates problems with the older browsers when rendering the line break.

    Horizontal line <hr>

    They are used to visually break-up sections of a document where <hr> tag creates a line from the current position in the document to the right margin and breaks the line accordingly.

    Writing your first web page

    You only need a simple editor to write a web page.

    Examples of text editors includes:

    • Notepad
    • komodo Edit
    • sublime Text
    • Notepad++
    • Atom
    • Brackets
    • TextEdit
    • Bluefish
    • BBEdit
    • vim
    • JEdit
    • Emacs
    • Text Wrangler among others

    Let us use a simple notepad that is common in most of windows computer.

    go to your startup menu and type, notepad

    Type the sentences between the tags as shown. Note that the last tag to use is the first one to close.

    Save the file with name startingHtml.html as shown

    the title bar changes from “untitled” into the name we have given it.

    locate the file, right click it and open with your favorite browser.

    You should see your page rendered on your browser as shown

    congratulations! You have created your first web page

    Related topics