get an info from a text file and display it
Posted: Sat Jan 17, 2015 3:25 pm
hi there, i'm new to php so please bear with me
i'm trying to get an info from a text file and display it
[info.txt]
miko,male,japan
kate,female,england
akira,female,japan
i want to display the names only depending on which info i choose in a form
if i choose male and japan, it will display miko
if i choose female and england, it will display kate
if i choose female and japan, it will display akira
here's my code:
Thanks a lot 
i'm trying to get an info from a text file and display it
[info.txt]
miko,male,japan
kate,female,england
akira,female,japan
i want to display the names only depending on which info i choose in a form
if i choose male and japan, it will display miko
if i choose female and england, it will display kate
if i choose female and japan, it will display akira
here's my code:
Code: Select all
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method=post>
Gender: <input type="text" name="gender">
Location: <input type="text" name="location">
<input type="submit" name="submit" value="SUBMIT">
</form>
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST")
{
$gender = $_POST['gender'];
$location = $_POST['location'];
$selected = $gender . ',' . $location;
$lists = file('info.txt');
$search = $selected;
$found=false;
foreach ($lists as $list)
{
if(strpos($list, $search) !== false)
{
$found=true;
echo 'name'; //this is where i don't know how to insert a name from the info.txt
}
}
if(!$found)
{
echo "No match";
}
}
?>