Jump to content

[SOLVED] If and ElseIf


Daney11

Recommended Posts

Hey guys,

 

Im using

 

if (eregi ('^[[:alpha:]\.\'\-]{2,80}$', stripslashes(trim($_POST['result_link'])))) {
   $result_link = escape_data($_POST['result_link']);
} else {
   $result_link = FALSE;
   $errors[] = 'Please Enter A Link';
       }

which is working fine. BUT im not sure how to add 2 links into it.

for example.

if (eregi ('^[[:alpha:]\.\'\-]{2,80}$', stripslashes(trim($_POST['result_link'])), stripslashes(trim($_POST['result_link1'])), )) {
   $result_link = escape_data($_POST['result_link']);
} else {
   $result_link = FALSE;
   $errors[] = 'Please Enter A Link';
       }

 

doesnt work.

 

ANyone any ideas?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/90062-solved-if-and-elseif/
Share on other sites

Check the documentation for eregi, it only takes 1 string parameter http://uk3.php.net/eregi

If you want to perform this eregi comparison on more than one string, i.e. secret line and secret link1

then you need to do it for each of them.

e.g.

if (eregi ('^[[:alpha:]\.\'\-]{2,80}$', stripslashes(trim($_POST['result_link']))) && eregi ('^[[:alpha:]\.\'\-]{2,80}$', stripslashes(trim($_POST['result_link1'])))) { ...

Link to comment
https://forums.phpfreaks.com/topic/90062-solved-if-and-elseif/#findComment-461759
Share on other sites

What Error?

Maybe you should split this out into a function and use that instead...

 

function performTest($value){
  $value = stripslashes($value);
  $value = trim($value);
  if (eregi ('^[[:alpha:]\.\'\-]{2,80}$', $value)) {
    return true;
  }
  return false;
}

if(performTest($_POST['result_link']) AND performTest($_POST['result_link1'])){
  $result_link = escape_data($_POST['result_link']);
} else {
  $result_link = FALSE;
  $errors[] = 'Please Enter A Link';
}

Link to comment
https://forums.phpfreaks.com/topic/90062-solved-if-and-elseif/#findComment-461771
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.