How can you check if a record exists in a MySQL database using PHP?

To check if a record exists in a MySQL database using PHP, you can execute a SELECT query with a WHERE clause that matches the specific criteria of the record you are looking for. If the query returns any rows, then the record exists in the database.

<?php
// Connect to the database
$connection = mysqli_connect("localhost", "username", "password", "database");

// Check connection
if (!$connection) {
    die("Connection failed: " . mysqli_connect_error());
}

// Check if a record exists
$sql = "SELECT * FROM table_name WHERE column_name = 'value'";
$result = mysqli_query($connection, $sql);

if (mysqli_num_rows($result) > 0) {
    echo "Record exists in the database";
} else {
    echo "Record does not exist in the database";
}

// Close connection
mysqli_close($connection);
?>