How can PHP scripts be effectively utilized to create a "Link Verzeichnis" feature on a website?

To create a "Link Verzeichnis" feature on a website using PHP scripts, you can create a form where users can submit their links along with a description. The submitted links can be stored in a database and displayed on the website in a structured format. Users can then browse through the links and descriptions to find relevant resources.

<?php
// Connect to the database
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "link_verzeichnis";

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

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

// Process form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $link = $_POST['link'];
    $description = $_POST['description'];

    // Insert the submitted link into the database
    $sql = "INSERT INTO links (link, description) VALUES ('$link', '$description')";

    if ($conn->query($sql) === TRUE) {
        echo "Link added successfully";
    } else {
        echo "Error: " . $sql . "<br>" . $conn->error;
    }
}

// Display the links from the database
$sql = "SELECT * FROM links";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    while($row = $result->fetch_assoc()) {
        echo "Link: " . $row["link"]. " - Description: " . $row["description"]. "<br>";
    }
} else {
    echo "0 results";
}

$conn->close();
?>