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();
?>
Keywords
Related Questions
- What could be causing the "Call to undefined function mysql_connect()" error when trying to run a PHP forum on a production server?
- What are the best practices for setting the MySQL connection to UTF-8 in a PHP application?
- Are there any specific PHP functions or methods that can simplify the process of adjusting column widths based on weightings?