Re: elseif

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Mon, Jan 27, 2003 at 06:26:06PM -0600, Addison Ellis wrote:
> 
> hello and thank you for your time.
> 	will the below work to check if one field or the other is 
> filled in upon submission? either contact_phone or contact_email is 
> required but not both. best, addison

I would use something like:

$error = "";
if (strlen(trim($name)) < 1) {
	$error .= "<li>You must enter a company name.\n";
}
...
if (! ($contact_phone || $contact_email) ) {
    $error .= "<li>You must enter a contact phone number or email address.\n";
}
if (strlen(trim($contact_email)) > 0 && eregi('[a-z0-9_.-]+@([a-z0-9]+\.)+[a-z][a-z]+',$contact_email)) {
    $error .= "<li>Email address has an invalid format.\n";
}
if (!$error) {
	$q = "INSERT INTO stores blah blah";
	...
}

> $error = "";
> if ($name == "")
> 	{
> 	$error = "$error<LI>You must enter a company name.</LI>";
> 	}
> if ($address == "")
>          {
>          $error = "$error<LI>You must enter an address.</LI>";
>          }
> if ($city == "")
>          {
>          $error = "$error<LI>You must enter a city.</LI>";
>          }
> if ($state == "")
>          {
>          $error = "$error<LI>You must enter a state.</LI>";
>          }
> if ($zip == "")
>          {
>          $error = "$error<LI>You must enter a zip.</LI>";
>          }
> if ($contact_phone == "")
>          {
>          $error = "$error<LI>You must enter a contact phone number or 
> email address.</LI>";
>          }
> elseif ($contact_email == "")
>          {
>          $error = "$error<LI>You must enter a contact phone number or 
> email address.</LI>";
>          }
> if ($error == "")
> 	{
> 	$query = "insert into stores  set
> -- 
> Addison Ellis
> small independent publishing co.
> 114 B 29th Avenue North
> Nashville, TN 37203
> (615) 321-1791
> addison@bellsouth.net
> info@smipco.com
> subsidiaries of small independent publishing co.
> info@gloabaldog.com
> info@momandpocentral.com
-- 
  Paul Chvostek                                             <paul@it.ca>
  Operations / Abuse / Whatever
  it.canada, hosting and development                   http://www.it.ca/


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux