error find string from input field | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

error find string from input field

<form method="POST">     <input type="text" name="search">     <input type="submit" value="Search"> </form> <?php if ($_SERVER['REQUEST_METHOD'] === 'POST') {   $search = $_POST['search'];   $lines = file('data.txt'); } foreach($lines as $line)   if(strpos($line, $search) !== false){     echo $line; } ?>

28th Feb 2023, 1:44 AM
Syafiq
Syafiq - avatar
1 Answer
0
if ($_SERVER['REQUEST_METHOD'] === 'POST') { $search = $_POST['search']; $lines = file('data.txt'); foreach($lines as $line) { if(strpos($line, $search) !== false){ echo $line; } } } I think that "foreach" is not correctly placed within the "if" statement. Try that code I give you with "foreach" inside "if"
8th Mar 2023, 7:16 AM
Minh Lưu
Minh Lưu - avatar