How to check empty columns in a table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
minds_gifts
Forum Commoner
Posts: 63
Joined: Mon Feb 10, 2003 4:23 am

How to check empty columns in a table

Post by minds_gifts »

Hello everybody,

How can i do this one??
If i press a button, i have to check if certain columns(fields) in a table are empty.If they are empty, i want to send an e-mail to the e-mail address which is already in this table.If there are no empty columns, then i want to do some calculation using another table.

Could somebody please tell me how should i do.

Many many thanks
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

EDIT: for the button part, i would make a link that would goto a page that did this in an if statement.

Code: Select all

<?php
    $link = mysql_connect("localhost", "***", "***") 
        or die("Could not connect"); 
    mysql_select_db("your_database", $link) or die("Could not select database"); 
    $query = MYSQL_QUERY("SELECT * FROM table WHERE field=''"); 
    while ($fetch=mysql_fetch_array($query)) { 
mail($email, "Your Subjet Here", "This email was sent for a reason, but I don't know why!");
}
?>
Now, all you need to modify is your connection username and password, where you're selecting from, and what field you want to check that is blank. i just tested this, and it works fine for me. Reply if you have troubles!
minds_gifts
Forum Commoner
Posts: 63
Joined: Mon Feb 10, 2003 4:23 am

Post by minds_gifts »

Thanks drachlen.How can i modify further my query if i want to check for certain columns in a table??For example, if i have a table with columns(first_name, last_name, email, city, zipcode and so on.....)
I want to check if my columns(zipcode, city are empty).

thanks
Drachlen
Forum Contributor
Posts: 153
Joined: Fri Apr 25, 2003 1:16 am

Post by Drachlen »

Code: Select all

<?php
WHERE zipcode='' AND city=''
?>
in place of:

Code: Select all

<?php
WHERE field=''
?>
Post Reply