Jump to content

PHP Error checking


webmaster123

Recommended Posts

Hi All,

 

I am trying to add some error checking in my php script.

I have 2 fields that my members can input a web URL and the text for the URL.

I have noticed that some people will input only one of the fields and not the other.

Can you tell me how to put in an error checking so both fields are field in?

If a member inputs a URL in the URL field then they must also fill in the text field or if they fill in the text field then they must fill in the URL field.

If they do not fill in either then no error checking is needed.

Here is the php script I tried but it does not work.

 

if ($wtext > 1 || $wurl < 1){

        $error = true;

        $errormessage .= "<center><p class=tbox><b>You did not enter the Website URL.<br>Please enter the Website URL or remove the Website Text.</b></center><br><br>\n";

          }

if ($wtext < 1 || $wurl > 1){

        $error = true;

        $errormessage .= "<center><p class=tbox><b>You did not enter the Website Text.<br>Please enter the Website text or remove the Website URL.</b></center><br><br>\n";

          }

 

Link to comment
https://forums.phpfreaks.com/topic/118323-php-error-checking/
Share on other sites

Take a look at your bitwise operators.  The || means OR.  Try && or AND.  Probably not useful to you is the ^ operator.  One or the other but not both.  I dont use that one much, except for regular expressions...

 

if (  (isset($_POST['url']))  || ( (isset($_POST['field1of2'])) && (isset($_POST['field2of2'])) )  )

 

In this example, URL by itself is acceptable, OR both fileds1 and field2 are required...

Link to comment
https://forums.phpfreaks.com/topic/118323-php-error-checking/#findComment-609083
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.