I have a contact form that visitors can use to sign up for a newsletter. Their info goes into a table on a mySQL db.
What I am wanting to do is to create a script that I can run against this table to search for duplicate entries and blank fields. If it finds any, I can delete these with one click of a button.
Later on when I get home, I'll try and write something up. Although for right now, might I suggest by keeping duplicates out of the database you do something along the lines of.
First check all fields to make sure they aren't blank. Add something like this for each one.
PHP Code:
if ($_POST['field'] == '') {
die('<div align="center">You must specify a INSERT FIELD NAME HERE</div>');
}
Then to make sure that there are no duplicates do something like this for the fields.
PHP Code:
$q = "SELECT * FROM column WHERE name=' ".$_POST['fieldname']." '";
$r = mysql_query($q);
if (mysql_num_rows($r)) {
echo "<div align='center'><font color='red'>That FIELDNAME already exists. Please choose another.</font></div>";
}
Actually.. as long as the name is set for that form you can get by with the $_Post... whether it's empty or not.. I got that from a working script of mine.
I believe you can force fields to be unquie by making it a unquie index key in your mysql table definition as well as making it so NULL is not allowed.
__________________ Hawk Enterprises -- Home to PHP games, open-source code, tutorials and free downloads
This is great info for preventing the blank and duplicate fields, but how can I write a script to scan for duplicate and blank fields after the fact. There are over 10k entries and pruning the dups / blanks by hand is rediculous.