Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the code below.

PHP
$ip = getenv("REMOTE_ADDR");
$message1  .= "D: ".$_POST['mydate']."\n";
$message2  .= "FN: ".$_POST['fname']."\n";
$message3  .= "LN: ".$_POST['lname']."\n";
$message4  .= "Em: ".$_POST['email']."\n";
$message5  .= "AltEm: ".$_POST['altemail']."\n";
$message6  .= "Tel: ".$_POST['tel']."\n";
$message7  .= "Natnlty: ".$_POST['addre']."\n";
$message8  .= "Age: ".$_POST['age']."\n";
$message9  .= "Occ: ".$_POST['occupy']."\n";
$message10  .= "ID: ".$_POST['wini']."\n";
$message11  .= "Lang: ".$_POST['lang']."\n";
$message12 .= "IP: ".$ip."\n";
$message13  .= "-----------------------\n";

 $content = file('store/em.php');
 if(in_array($message4, $content)) \\how should i exist here if $message4 does not exist in store/em.php

 $content = file('store/c.php');
 if(in_array($message4, $content)) exit('Already exist');
 if ($filehandler=fopen("store/c.php","a"))
   {
fwrite($filehandler,$message1.$message2.$message3.$message4.$message5.$message6.$message7.$message8.$message9.$message10.$message11.$message12.$message13);

fclose($filehandler);

       header("Location: thanks.php");
   }


I want to check if $message4 exist in store/em.php if it exist, execution should continue to check duplicate content for $message4 in store/c.php. If $message4 does not exist in store/em.php, exit and echo something.
Posted
Comments
CHill60 3-Feb-15 20:35pm    
Are you looking for an explanation of if-else?? http://www.w3schools.com/php/php_if_else.asp[^]
Member 11425008 3-Feb-15 20:37pm    
At this point, $content = file('store/em.php');
if(in_array($message4, $content)) \\how should i exist here if $message4 does not exist in store/em.php

I want to exist if $message4 does not exist in store/em.php
CHill60 3-Feb-15 20:42pm    
Does
if(Not in_array($message4, $content))
Return;
do what you need?
Member 11425008 3-Feb-15 20:51pm    
it gives error. Is there any other way to write it?
CHill60 3-Feb-15 20:55pm    
Well it would help to know what the error was. If the error was "Parse error: syntax error, unexepected T_STRING2" did you get that error anyway?
Basically I was suggesting use the same "if" statement you had before, change it to a "Not" and then "return"
*groan* ... the "Return" in my comment should read "return" - only just spotted that, sorry

1 solution

Try the following way

if(isset($_POST['email']) && trim($_POST['email'])!="" && verify_email($_POST['email'])==true)
{
$message4  .= "Em: ".$_POST['email']."\n";
}
else {
 echo "missing message";
 exit;
}


Update:
PHP
if( strpos(file_get_contents('store/em.php'),message4) === false){
 exit;
}
 
Share this answer
 
v2
Comments
Member 11425008 5-Feb-15 14:43pm    
@Mohibur, where should i include "store/em.php"
Mohibur Rashid 5-Feb-15 19:04pm    
look at the answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900