Fouten weergeven

Gestart doorWouter3 reacties24 weergaven

4 berichten · pagina 1 van 1

Wouter

Lid · Topicstarter

Berichten
3.540
Reputatie
0
Punten
0,01
Lid sinds
Laatst gezien
Hallone2xs

Bij de verwerking van een registreerformulier heb ik gewerkt met volgende structuur.
Als er een fout is, dan geeft $fout de foutmelding weer

[COLOR= #0000BB]<?php[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$voorwaarde[/COLOR] [COLOR= #007700]!=[/COLOR] [COLOR= #0000BB]$voorwaarde2[/COLOR][COLOR= #007700]){[/COLOR]
[COLOR= #0000BB]$fout[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"blablabla"[/COLOR][COLOR= #007700];
}[/COLOR]
[URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$voorwaarde3[/COLOR] [COLOR= #007700]!=[/COLOR] [COLOR= #0000BB]$voorwaarde4[/COLOR][COLOR= #007700]){[/COLOR]
[COLOR= #0000BB]$fout[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]"blablabla2"[/COLOR][COLOR= #007700];
}[/COLOR]
?>


Nu, als ik zorg dat allebei de voorwaarden niet kloppen, geeft het script alleen de eerste. Hoe kan ik ervoor zorgen dat het script ze allemaal geeft?

Met vriendelijke groeten
Wouter
0
Berichten
515
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
$fout = array();

Daarna voor elke fout

$fout[] = blabla;

Daarna om laten zien

foreach ($fout as $ error) {
echo
  • .$error.
  • ; }

    Ff snel getyped xit op mobiel

    Nog even wat extra uitleg.

    wat je hier eigenlijk aan het doen bent (scenario allebei fout)

    Invoer 1 is niet goed -> fout is dit -> als invoer 2 ook niet goed is -> fout is de andere (variabele fout wijzigt zichzelf dus waardoor je maar 1 waarde hebt)
    0
    Berichten
    262
    Reputatie
    0
    Punten
    0,00
    Lid sinds
    Laatst gezien
    uitgebruider uitleg van justafool vind je ander wel duidelijk hier:
    http://www.phptuts.nl/view/39/8/
    0
    Berichten
    515
    Reputatie
    0
    Punten
    0,00
    Lid sinds
    Laatst gezien
    Jah indd simonyummie kan wel uitgebreider maar is wat lastig op mobielyummie
    edit :

    Naja ik verveel me zit nu op laptop dus kan je wel ff voorbeeld geven

    [COLOR= #0000BB]<?php[/COLOR]
    [COLOR= #FF8000]//Array maken van $fout[/COLOR]
    [COLOR= #0000BB]$fout[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/array"]array[/URL][COLOR= #007700]();[/COLOR]
    
    [COLOR= #FF8000]//Eerste controle[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$voorwaarde[/COLOR] [COLOR= #007700]!=[/COLOR] [COLOR= #0000BB]$voorwaarde2[/COLOR][COLOR= #007700]){[/COLOR]
    
        [COLOR= #0000BB]$fout[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #DD0000]"blablabla"[/COLOR][COLOR= #007700];
    
    }[/COLOR]
    
    [COLOR= #FF8000]//Tweede controle[/COLOR]
    [URL="http://www.php.net/if"]if[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$voorwaarde3[/COLOR] [COLOR= #007700]!=[/COLOR] [COLOR= #0000BB]$voorwaarde4[/COLOR][COLOR= #007700]){[/COLOR]
    
        [COLOR= #0000BB]$fout[/COLOR][COLOR= #007700][] =[/COLOR] [COLOR= #DD0000]"blablabla2"[/COLOR][COLOR= #007700];
    
    }[/COLOR]
    
    [COLOR= #FF8000]//Tellen hoeveel fouten er zijn[/COLOR]
    
    [COLOR= #0000BB]$count[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/count"]count[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$fout[/COLOR][COLOR= #007700]);[/COLOR]
    
    [COLOR= #FF8000]//Is er wat fout zo ja maak een lijstje aan[/COLOR]
    [URL="http://www.php.net/if"]if[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$count[/COLOR] [COLOR= #007700]>[/COLOR] [COLOR= #0000BB]0[/COLOR][COLOR= #007700]) {[/COLOR]
    
        [COLOR= #FF8000]//Opsomming aanmaken[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]<ul>[/COLOR][COLOR= #007700];[/COLOR]
        [COLOR= #FF8000]//elke fout dat in de array zit in een opsomming zetten[/COLOR]
        [URL="http://www.php.net/foreach"]foreach[/URL] [COLOR= #007700]([/COLOR][COLOR= #0000BB]$fout[/COLOR] [COLOR= #007700]as[/COLOR] [COLOR= #0000BB]$error[/COLOR][COLOR= #007700]) {[/COLOR]
    
            [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]
    
                <li>[/COLOR][COLOR= #007700].[/COLOR][COLOR= #0000BB]$error[/COLOR][COLOR= #007700].[/COLOR][COLOR= #DD0000]</li>
    
            [/COLOR][COLOR= #007700];
        }[/COLOR]
        [COLOR= #FF8000]//Opsomming sluiten[/COLOR]
        [URL="http://www.php.net/echo"]echo[/URL] [COLOR= #DD0000]</ul>[/COLOR][COLOR= #007700];
        
    }[/COLOR]
    [COLOR= #FF8000]//Is er geen fout voer dan het volgende uit[/COLOR]
    [URL="http://www.php.net/else"]else[/URL] [COLOR= #007700]{[/COLOR]
        [COLOR= #FF8000]//Hier de actie neerzetten om de registratie te voltooien[/COLOR]
    [COLOR= #007700]}[/COLOR]
        
    
    
    ?>
    0

    Jouw reactie

    Deel je idee, stel een vraag of help een ander verder.

    Editor laden…

    Praat mee met de One2xs-community.

    Inloggen om te reageren