Jump to content

eregi echo problem


spillage

Recommended Posts

I have this code for checking emails in form and it all works well except for one thing as soon as the php page is opened the form is empty as it should be so I get the first message displayed. New to coding and scratching my head trying to work out how to stop this happening. Would be nice to echo some welcome text first.


   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);
           }

?>

 

Thanks

 

Spill

Link to comment
https://forums.phpfreaks.com/topic/102489-eregi-echo-problem/
Share on other sites

Either ive added the extra code in the wrong place of somthing isnt right. I have also put it at the very start of the code.

It seems to wipe out any echos within the{} and will not write anythign to the file. the value of the submit button is "send_friend".

 

Thanks

 

<?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";
@ $fp= fopen ("$DOCUMENT_ROOT/rcfriend.txt",'a+');


      echo "Your email is: ".$cust.'</br>';

if ($_POST["send_friend"])
{
   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);
           }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/102489-eregi-echo-problem/#findComment-524827
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.