spillage Posted April 23, 2008 Share Posted April 23, 2008 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 More sharing options...
ublapach Posted April 23, 2008 Share Posted April 23, 2008 where your else if line is there needs to be else if { then the next if statement and make sure you close it Link to comment https://forums.phpfreaks.com/topic/102616-noob-dumb-question-on-elseif/#findComment-525528 Share on other sites More sharing options...
spillage Posted April 23, 2008 Author Share Posted April 23, 2008 sorry being really dumb any chance you could show the adjustment on my code as have tried this all ways without success. cheers Link to comment https://forums.phpfreaks.com/topic/102616-noob-dumb-question-on-elseif/#findComment-525535 Share on other sites More sharing options...
ublapach Posted April 23, 2008 Share Posted April 23, 2008 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); } Link to comment https://forums.phpfreaks.com/topic/102616-noob-dumb-question-on-elseif/#findComment-525537 Share on other sites More sharing options...
spillage Posted April 23, 2008 Author Share Posted April 23, 2008 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); } ?> Link to comment https://forums.phpfreaks.com/topic/102616-noob-dumb-question-on-elseif/#findComment-525554 Share on other sites More sharing options...
ublapach Posted April 23, 2008 Share Posted April 23, 2008 whats the error Link to comment https://forums.phpfreaks.com/topic/102616-noob-dumb-question-on-elseif/#findComment-525558 Share on other sites More sharing options...
ublapach Posted April 23, 2008 Share Posted April 23, 2008 you have this line in there twice if ($friend==0) { echo "welcome please provide your friends email below."; } Link to comment https://forums.phpfreaks.com/topic/102616-noob-dumb-question-on-elseif/#findComment-525561 Share on other sites More sharing options...
spillage Posted April 24, 2008 Author Share Posted April 24, 2008 error is Parse error: syntax error, unexpected '{', expecting '(' in C:\wamp\www\mail01.php on line 44 cheers Link to comment https://forums.phpfreaks.com/topic/102616-noob-dumb-question-on-elseif/#findComment-525928 Share on other sites More sharing options...
ublapach Posted April 26, 2008 Share Posted April 26, 2008 there isnt 44 lines of code Link to comment https://forums.phpfreaks.com/topic/102616-noob-dumb-question-on-elseif/#findComment-527714 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.