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

    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
                    echo "That post already exists.";

PHP Tricks 2016-06-14View: 1797

Categories: PHP Tricks


Leave a comment