Current location: Hot Scripts Forums » Programming Languages » PHP » Remove Duplicate and Blank Fields


Remove Duplicate and Blank Fields

Reply
  #1 (permalink)  
Old 07-29-04, 10:59 AM
digitalje5u5 digitalje5u5 is offline
Newbie Coder
 
Join Date: May 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
Remove Duplicate and Blank Fields

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.

Thanks,
/DJ
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 07-29-04, 11:13 AM
AndrewWest AndrewWest is offline
Newbie Coder
 
Join Date: Jun 2004
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
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>";

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 07-29-04, 09:51 PM
JasonMichael's Avatar
JasonMichael JasonMichael is offline
Newbie Coder
 
Join Date: Jul 2004
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
If you're going to check if fields are filled out, as above, you could also just do:

if (isset($_POST['xxYourfieldName'])) {
blah blah
}

because if nothing is entered, a $_POST variable won't be created for that field from the form.

Also note that if your form has a name, you have to do the following:

if (isset($_POST['xxxYourFormNamexxx']['xxxYourFieldNamexxx'])) {
blah blah blah
}
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 07-29-04, 10:00 PM
AndrewWest AndrewWest is offline
Newbie Coder
 
Join Date: Jun 2004
Posts: 21
Thanks: 0
Thanked 0 Times in 0 Posts
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.

http://svcsports.com/demo/

Go ahead and register.. don't full out the name.. and you'll see. I do it the same way I exampled for him.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 07-30-04, 01:43 AM
infinitylimit's Avatar
infinitylimit infinitylimit is offline
Code Guru
 
Join Date: Jun 2004
Location: Oregon
Posts: 758
Thanks: 0
Thanked 0 Times in 0 Posts
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 08-06-04, 12:33 PM
digitalje5u5 digitalje5u5 is offline
Newbie Coder
 
Join Date: May 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
*bump bump
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 08-06-04, 03:29 PM
digitalje5u5 digitalje5u5 is offline
Newbie Coder
 
Join Date: May 2004
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
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.

TIA for the help.

/DJ
__________________
<a href="http://www.procreations.org">Scott Thomas</a><br>
<a href="mailto:scott.thomas@beasleyallen.com">Scott. Thomas@beasleyallen.com</a><br>
<a href="http://www.beasleyallen.com">Personal Injury Attorney</a>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump


All times are GMT -5. The time now is 07:00 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.