0
Hello!
From a csv file, because after doing submit
On the form do I get the return with the correct values?
If the $_POST
countries are the same $registo[1]
, wanted to return the $registration[0] and $registo[2]
corresponding to thatregisto[1]
<?php
$br = "</br>";
$file = fopen("paises.txt", "r");
$codigo = (isset($_POST['codigo']) ? $_POST['codigo'] : null);
$pais = (isset($_POST['pais']) ? $_POST['pais'] : null);
$capital = (isset($_POST['capital']) ? $_POST['capital'] : null);
$cod = "";
$cap = "";
if (array_key_exists("pais", $_POST)) {
echo "<table border='1'><th>Pais</th>";
while (!feof($file)) {
$registo = fgetcsv($file);
if ($pais = $registo[1]) {
$cod = $registo[0];
$cap = $registo[2];
}
echo"<tr>";
echo"<td>" . $registo[1] . "</td>";
echo"</tr>";
}
echo "</table>";
fclose($file);
}
?>
<?php
$br = "</br>";
if ($_POST) {
echo "Codigo do pais escolhido: " . $cod . "<br>";
echo "Capital: " . $cap . " - " . $registo[1] . "-" . $cod . "<br>";
} else {
?>
<form action="eta15_2teste.php" method="post">
Pais: <input type="text" name="pais"><br>
<input type="Submit" name="enviar" value="Enviar">
</form>
<?php
}
?>
Always returns the values of $registo[0]
and $registo[2]
last line of the file
someone might try to help?
– Mario Caeiro
I don’t know if this is it, but your if is wrong "if( $pais = $registo[1] )". You are assigning $registration[1] to $pais
– Denis Rudnei de Souza
@Denisrudneiuza I just wanted when filling the country in the form, to look in the $registration[1] if it existed, if it existed to echo the country’s code and capital
– Mario Caeiro