23 Like(s)
|
Check if Record Exists in mysql php.
Checking to see if a record exists in the database php
check if value already exists in MySQL php
<?php
function post_exists($title)
global $connection;
$title = $title;
$query = mysqli_query($connection, "SELECT COUNT(*) FROM Your-table-name WHERE title = '{$title}'");
$record = mysqli_fetch_array($query);
$data = $record[0];
if ($data == 0) {
return false;
} else {
return true;
}
}
//call this function and check then message
if(post_exists($title)){
echo "That post already exists.";
}
?>
Categories: PHP Tricks
Leave a comment