php - Can't perform simple array search from array -


i have program failing because it's not finding $post in search of array, it's continuing add each time. have used other suggested method of using foreach loop, strpos, such as: if (strpos($data, $posts) !== false), , work find $post, find rest , run against in data/array. hence why search array, if it's not there add it, if is, it's there or checking in... i've spent 3 days using in_array, array_search, etc, i'm asking help...

<html> <body> <?php  $post = $_post['name']; $data = file("data.txt"); if (in_array($post, $data)) {     echo "$post checking in..."; } else {     echo "adding $data...";     $data = fopen("data.txt", "a+");     fwrite($data, $post.php_eol);     fclose($data); } $data = file("data.txt"); foreach ($data $d) {     echo $d; }  ?>  </body> </html> 

tclient.html

<html> <body>  <form action="test4.php" method="post"> name: <input type="text" name="name"><br> <input type="submit"> </form>  </body> </html> 

data.txt

names john doe 

the value in $post doesn't have new line @ end. can specify not include new lines when use file().

file("data.txt", file_ignore_new_lines); 

Comments