Help with $_post and loops.

How can i prevent the ELSE for echoing Not found as default? It’s printing it when i load the page or after submitting. How to fix this? Need help. thanks.

<?php if ( isset ( $_POST["name"] ) ) { $osoitekirja = array("etunimi" => array("john", "will", "jack"), "sukunimi" => array("smith", "bauer", "wayne")); foreach ( $osoitekirja as $nimet => $nimien_taulukot) { foreach ( $nimien_taulukot as $name ) { if ( $_POST = $name ) { echo "found"; } else { echo "Not found"; } } } } ?> First name:

I’m not sure but I assume this is what you were going for:

foreach ($nimien_taulukot as $name) {
if ($_POST[‘name’] == $name) {
echo “found”;

I know but when th page loads first time it will only display the text box. Then i type name that is NOT in the array it will echo out “not found” but at moment it is echoing Not found everytime.

Sorry I guess I don’t understand what you are trying to do.

I’ll point out that your syntax here is wrong:

[php]$_POST = $name[/php]

You are comparing an array $_POST to a string $name. It will always be false.

Sponsor our Newsletter | Privacy Policy | Terms of Service