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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.