Jump to content

Noob dumb question on elseif


spillage

Recommended Posts

Ok sat down for another night of banging my head against the wall and drinking some good old malt.

All I am after is for my php page to echo a simple welcome message and then if nothing is submitted

an error message is echoed or correct data is submitted and a well done message is echoed.

 

but if I try:

if ($friend==0)
{
echo "welcome please provide your friends email below.";
}


elseif (!eregi('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$',
            stripslashes(trim($friend))))
            {
			echo "<p>Please enter your friends valid email below:";
			echo '</br>';
		}

    else

           {
   	           echo "<p>Thank you</p>";
               echo "<p>Your email has been submitted</p>";
           echo "<p>Please submit another email or close your browser.</p></br>";
           fwrite ($fp,$output, strlen($output));
               fclose($fp);
           }

 

All that is echoed is the welcome bit even if email is incorrect.

If I remove the if ($friend==0) bit and just have if (!eregi***** then the

please enter your friends valid email shows straight away on the page.

 

If anyone can see my stupid mistake then please rub my nose in it.

 

Thanks

 

Spill

Link to comment
https://forums.phpfreaks.com/topic/102616-noob-dumb-question-on-elseif/
Share on other sites

if ($friend==0)
{
echo "welcome please provide your friends email below.";
}


else if {(!eregi('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$',
            stripslashes(trim($friend))))
            
			echo "<p>Please enter your friends valid email below:";
			echo '</br>';
		}

    else

           {
   	           echo "<p>Thank you</p>";
               echo "<p>Your email has been submitted</p>";
           echo "<p>Please submit another email or close your browser.</p></br>";
           fwrite ($fp,$output, strlen($output));
               fclose($fp);
           }

for some reason that just throws up an error on the elseif line. Have included all the code incase it helps.

<?php
session_start();
if (isset($_POST['email'])) {
  $_SESSION['email']=$_POST['email'];
}
$cust = $_SESSION['email'];
$DOCUMENT_ROOT=$_SERVER['DOCUMENT_ROOT'];

$friend=$_POST["address"];
$output= $cust."\t".$friend."\r\n";
echo "Your email is: ".$cust;
@ $fp= fopen ("$DOCUMENT_ROOT/rcfriend.txt",'a+');
if ($friend==0)
{
echo "welcome please provide your friends email below.";
}


if ($friend==0)
{
echo "welcome please provide your friends email below.";
}


else if {(!eregi('^[[:alnum:]][a-z0-9_\.\-]*@[a-z0-9\.\-]+\.[a-z]{2,4}$',
            stripslashes(trim($friend))))
            
			echo "<p>Please enter your friends valid email below:";
			echo '</br>';
		}

    else

           {
   	           echo "<p>Thank you</p>";
               echo "<p>Your email has been submitted</p>";
           echo "<p>Please submit another email or close your browser.</p></br>";
           fwrite ($fp,$output, strlen($output));
               fclose($fp);
           }
?>

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.