i have a php code that read from text file an compare the user input with its content.
the problem is that the system read from the text file but doesn't compare
what is the error and is their another method?
testfile.txt
test admin people bob321 danyjd ajb
code:
<?php
if(isset($_POST["Search"]))
{
$data= file('testfile.txt');
$accessData = array();
foreach($data as $line){
list($dataFile1) = explode(',', $line);
}
$dataInput = isset($_POST['name'])? $_POST['name']:'';
if(array_key_exists($dataInput, $accessData)){
echo "text exist";
}
else{
echo "text doesn't exist";
}
}
?>
<html>
<head>
</head>
<body>
<form action="test2.php" method="post">
<p>enter your string <input type ="text" id = "idName" name="name" /></p>
<p><input type ="Submit" name="Search" /></p>
</form>
</body>
</html>
$accessDatais an empty array...list($dataFile1)shouldn't that belist($accessData)?$accessData[]instead oflist($dataFile1)? Using list here feels redundent