Tag Archives: update

Finding duplicate records in MySQL


I have added a new function to the add bookmarks & category form to look for duplicate URL’s in the database, and stop them being added into the bookmarks table

First step is to move if(empty($errors)) from above the main query to insert the bookmark into the table to below the input validation section. We then add the test for unique URL just below the if(empty($errors))

if(empty($errors)) {

// checks for duplicate URL

$q = "SELECT bmarks_id FROM b_marks WHERE baddy='$ba'";
$stmt = mysqli_query ($dbc, $q);

if (mysqli_num_rows($stmt) == 0) {

//check if new category is being entered.

This will check the database table for a match of URL’s, if one is found we echo the below which is inserted as the last item when confirming the results of the query, otherwise the query will run.

} else {
echo '<p>URL has already been entered</p>';
}

As you can see I have changed the layout & formated the forms (you can only see this if you login which is just me at the min), I will post all the new files soon once I have cleaned it all up.