PoonDaddy007

Senior member
Dec 17, 2000
246
0
0
Quick question for PHP.

I have page where people go and register for a service. They enter in their names, addresses, email, etc. I need to check if the fields are empty or not. Not if the information is valid, just see if the fields are not empty. If it is empty then it will show a different page that says "please fill out all the information." if everything is filled in then it will jus continue with the process. Can anyone tell me how to set this up in PHP or an example of where it is implemented?

Thanks
 

randal

Golden Member
Jun 3, 2001
1,890
0
76
like so ...

<form action=somefile.php method=post>
<input type=textbox name=field>
<input type=submit>
</form>

somefile.php:

<?php
if (!isset($_POST['field'])) {
print "field is empty"; }
else {
print "field is " . $_POST['field']; }
?>

instead of !isset, you could use empty(), or strlen() or even just if($_POST[field]) {} ...
randal
 

Czar

Lifer
Oct 9, 1999
28,510
0
0
first you have a form

<input type=text name=email>

then in the php page you have this

if(isset($submit)) { //if the submit button has been pressed
__if(!isset($email) { //if there email is not set
____print("email is missing"); //do what happens then
__}
}

if it doesnt work like that then thats because php sets the $email varible as "" so its still set but has nothing in it, then you do the same check just using strlen() and check if its longer than 0.
 

randal

Golden Member
Jun 3, 2001
1,890
0
76
if(isset($submit)) { //if the submit button has been pressed
__if(!isset($email) { //if there email is not set
____print("email is missing"); //do what happens then
__}
}

Please note that in PHP v4+ you cannot access POST or GET variables directly like that -- they must be accessed via the globally available $_POST and $_GET arrays.

randal

 

Czar

Lifer
Oct 9, 1999
28,510
0
0
Originally posted by: randal
if(isset($submit)) { //if the submit button has been pressed
__if(!isset($email) { //if there email is not set
____print("email is missing"); //do what happens then
__}
}

Please note that in PHP v4+ you cannot access POST or GET variables directly like that -- they must be accessed via the globally available $_POST and $_GET arrays.

randal
yeah, I havent been doing much php lately so I still havent gotten used to it to $_post and $_get :p
 

polson

Junior Member
Nov 21, 2002
1
0
0
Just as a fyi jic: The ability to access variables as $foo instead of, for example, $_POST['foo'], is not due to what PHP version you are using but rather it has to do with the PHP directive register_globals. This is set in your php configuration file which is called php.ini As of PHP 4.2.0 register_globals defaults to OFF. Before this time it was ON. ON is what creates $foo. This directive can be turned on or off in any php version but it's recommended to code assuming it's off as that way your code will work regardless. On a related note, autoglobals (superglobals) were introduced in PHP 4.1.0 and before this time you'd use for example $HTTP_POST_VARS although they still work. See: http://www.php.net/variables.external