473,795 Members | 2,605 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

prevent blank data

How do I prevent blank data from being entered into a table?

For instance, the user fills out a form, but if a field is left blank, then
the entire entry won't be filled in. This isn't necessarily a form
validation thing, just that if all the fields are filled, then proceed to
enter data, if not then don't.

Thanks in advance!
Jul 17 '05 #1
7 3156
John wrote:
How do I prevent blank data from being entered into a table?

For instance, the user fills out a form, but if a field is left blank, then
the entire entry won't be filled in. This isn't necessarily a form
validation thing, just that if all the fields are filled, then proceed to
enter data, if not then don't.


<?php
$empty_fields = 0;
foreach ($_POST as $field) {
if (empty($field)) ++$empty_fields ;
}
if ($empty_fields == 0) {
// save to database
}
?>
HTH
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #2
Pedro Graca <he****@hotpop. com> wrote in
news:c4******** *****@ID-203069.news.uni-berlin.de:

<?php
$empty_fields = 0;
foreach ($_POST as $field) {
if (empty($field)) ++$empty_fields ;
}
if ($empty_fields == 0) {
// save to database
}
?>


hmm.. for some reason that's not working. My form is on the first page but
I'm not going to the form, I'm attempting to go to the second page directly
without hitting the first page at all. On the 2nd page is where the 2nd
data is being input into the table. I put that above code just above and
below the insert code but it's still not doing anything.

any suggestions? thanks again in advance :)

Jul 17 '05 #3
John <askformyemai l> wrote in news:Xn******** **********@216. 196.97.136:
Pedro Graca <he****@hotpop. com> wrote in
news:c4******** *****@ID-203069.news.uni-berlin.de:

<?php
$empty_fields = 0;
foreach ($_POST as $field) {
if (empty($field)) ++$empty_fields ;
}
if ($empty_fields == 0) {
// save to database
}
?>


hmm.. for some reason that's not working. My form is on the first page
but I'm not going to the form, I'm attempting to go to the second page
directly without hitting the first page at all. On the 2nd page is
where the 2nd data is being input into the table. I put that above
code just above and below the insert code but it's still not doing
anything.

any suggestions? thanks again in advance :)

just to follow up, i took your comments out and put in my insert code...
that's not doing anything... was there a different way to do it? thanks
again!

Jul 17 '05 #4
John wrote:
John <askformyemai l> wrote in news:Xn******** **********@216. 196.97.136:

Pedro Graca <he****@hotpop. com> wrote in
news:c4****** *******@ID-203069.news.uni-berlin.de:
<?php
$empty_field s = 0;
foreach ($_POST as $field) {
if (empty($field)) ++$empty_fields ;
}
if ($empty_fields == 0) {
// save to database
}
?>

hmm.. for some reason that's not working. My form is on the first page
but I'm not going to the form, I'm attempting to go to the second page
directly without hitting the first page at all. On the 2nd page is
where the 2nd data is being input into the table. I put that above
code just above and below the insert code but it's still not doing
anything.

any suggestions? thanks again in advance :)


just to follow up, i took your comments out and put in my insert code...
that's not doing anything... was there a different way to do it? thanks
again!

I wrote a little class to do it:

---
class chkEmpty {

/* Variables */
var $elements, $error, $errmsg;

/* Constructor */

function chkEmpty($eleme nts) {
if (is_null($eleme nts)) {
die("Error. Required arguments were not passed to this class.");
}

foreach ($elements as $key) {
if (strlen($_POST[$key]) < 1) {
$this->error = 1;
$this->errmsg = "Please fill in all required fields.";
break;
}
}
} // End chkEmpty()

} // End class chkEmpty
----

Then you call it like

$fullform = new chkEmpty(array( 'form', 'field', 'names', 'you',
'require', 'here'))

and then check if it returns an error

if ($fullform->error) {
echo $fullform->errmsg;
} else {
echo "A-ok!";
}

HTH,
Jay

Jul 17 '05 #5
Jay Moore <ad*****@isp.tl d> wrote in
news:hy******** ***********@twi ster.rdc-kc.rr.com:
I wrote a little class to do it:

<complicated code snipped>

ok wow, that is all so complicated.. I think you're overkilling this. I
don't need it to check the form, the form is on the first page. My insert
code is on page 2, the page that page 1 goes to when you click submit. It's
just I'm not clicking submit this time and just going to page2 manually.
When I do that blank info is being inserted into the table. I just want a
way that will check on that second page that if the data being entered the
table is blank or null then it won't be entered.

thanks in advance if you can help with this :)
Jul 17 '05 #6
John wrote:
I don't need it to check the form, the form is on the first page. My insert
code is on page 2, the page that page 1 goes to when you click submit. It's
just I'm not clicking submit this time and just going to page2 manually.
Only when you POST (by clicking SUBMIT) is data available to page2.
When I do that blank info is being inserted into the table. I just want a
way that will check on that second page that if the data being entered the
table is blank or null then it won't be entered.


<?php
if ($_SERVER['REQUEST_METHOD '] != 'POST') {
exit('You have to press SUBMIT for data to be available.');
} else {
// check for all non-empty fields
// and save to database
}
--
USENET would be a better place if everybody read: : mail address :
http://www.catb.org/~esr/faqs/smart-questions.html : is valid for :
http://www.netmeister.org/news/learn2quote2.html : "text/plain" :
http://www.expita.com/nomime.html : to 10K bytes :
Jul 17 '05 #7
Pedro Graca <he****@hotpop. com> wrote in
news:c4******** *****@ID-203069.news.uni-berlin.de:
John wrote:
I don't need it to check the form, the form is on the first page. My
insert code is on page 2, the page that page 1 goes to when you click
submit. It's just I'm not clicking submit this time and just going to
page2 manually.
Only when you POST (by clicking SUBMIT) is data available to page2.


Exactly, so when you go to page2 without going directly to page1 first then
there is no data that is able to be entered.. so a blank entry is being
reated.

When I do that blank info is being inserted into the table. I just
want a way that will check on that second page that if the data being
entered the table is blank or null then it won't be entered.


<?php
if ($_SERVER['REQUEST_METHOD '] != 'POST') {
exit('You have to press SUBMIT for data to be available.');
} else {
// check for all non-empty fields
// and save to database
}


Jul 17 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
14587
by: Catherine Jo Morgan | last post by:
Can I set it up so that a certain combination of fields can't contain the same entries, on another record? e.g. a combination of FirstName/LastName/address? Or FirstName/LastName/phone? Or FirstName/LastName/email? Or is it possible to allow this but to throw up an alert message? Warning that this person is probably already in the database? TIA
6
6588
by: Miguelito Bain | last post by:
hi everybody- i have a form with 2 fields on it that i want the user to fill out before he or she can save the record, close the record, or move to the next record, etc... here's the code i tried. if i just enter minutes and click close, the form closes. it seems to bypass my nested if statement.
1
2431
by: Stephen Adam | last post by:
Hi there, I have written a custom validation control which checks to see of an input field is not empty and contains only numeric data. I was using a regular expression validation control but was unable to get it fail if a field was blank. My problem now is that while my custom validation control will detect if a field matches my requirement and will display a error message if it doesnt, it wont stop it from being used and sent to my...
1
2176
by: Brian | last post by:
Hello - Is there a way to prevent the user from creating a blank row at the bottom of a datagrid? I want a read only grid that allows the user to view data but not select specific cells or create a blank row, etc. Thanks, Brian
24
7708
by: Charles Law | last post by:
When I click a button I don't want the click event to fire. Is this possible? In fact, what I would really like is to be able to intercept the click event, perform some action, and then prevent the click from passing through to the button. Any help or suggestions much appreciated. Charles
4
2218
by: sparks | last post by:
I am trying to fix a database that someone did about 4 yrs ago in access97. The main table just contains demographics and is on the main form of the database. It has a subform on a tab that contains the other information. it is set 1 to 1 in the relationships. simplify if I can
5
1513
by: rn5a | last post by:
A Web Form has a TextBox within a DataGrid wherein users are expected to enter only whole numbers. It should be validated so that the TextBox doesn't remain blank or any non-numeric data is entered in the TextBox. If the TextBox doesn't get validated, I want to display messages to the user which should be as precise as possible for the user to easily identify where he erred. This is how I did it: ...
3
2963
by: groups2 | last post by:
When you press the down key while in an input field the default behavior for some event creates a dropdown of the previously input text. What event creates that behavior and how do I stop it ? For example, to prevent ANY type of default behavior when clicking ANY key, I thought this would work, but the dropdown still occurs. What am I doing wrong ? In html file:<body onload="registersearch()" >
7
4556
by: perryche | last post by:
Is there a way with MS Access 2002 and above to prevent people importing from a blank Database the tables in another database? I have done a lot of searches but there isn't really a solution that will work for me. Would someone explain how to build a RWOP Query in 2002 and what it does exactly? I can prevent an access to a query, but, what if people just tap into your table, and bypass your query? May be I misunderstood what it does. ...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10213
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10163
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10000
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6780
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3722
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.