Script loop terug van boven af door wegens foutief criterium

Overzicht Reageren

Sponsored by: Vacatures door Monsterboard

Ewergreen php

ewergreen php

24/08/2010 21:52:45
Quote Anchor link
Ok, bijkomende vraag. Eentje waarvan ik halvelings weet dat ik er zelf uit zou moeten geraken, maar waar ik dus toch niet uit geraak.

Ik geef in het begin een criterium op (!ctype...), maar als ik mijn twee form submit, dan is NumberOfOptions niet meer ingevuld. DUS loopt hij het scriptje weer van boven af aan door. Ik heb al wat gerommeld met sessions, maar kom er niet uit. Kan iemand even helpen?

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php

    if(!ctype_digit($_POST['NumberOfOptions'])){ //If numerical input was given, don't show the form
        echo "Vul hieronder het aantal antwoorden in:<br />";
        echo "<form action='poll_array.php' method='post'>";
        echo "<input type='text' name='NumberOfOptions'>";
        echo "<input type='submit' value='Maak poll'>";
        echo "</form>";
    }

    else {
        $NumberOfOptions = (int)$_POST['NumberOfOptions'];
        if ($NumberOfOptions <= 1){ //Check for at least 2 answers.
            echo 'Kies minstens twee opties.';
        }

        else {
            echo '<div id="ShowOptions">';
            echo "<form action='poll_array.php' method='post'>";
            echo "Vul hieronder de antwoorden in:<br />";
            for($count = 1; $count <= $NumberOfOptions; $count++) {//Print desired amount of input options
                echo "Antwoord optie #".$count.": <input name='question[$count]' type='text'><br />";
            }

            echo "<input type='submit' value='Submit optie'>"; //Remember the given options
            echo "</form>";
            echo "</div>";
        }

        
            if(!empty($_POST['questions']) && empty($_POST['NumberOfOptions'])){
            echo "hello";
            
            }
        

    }

?>
 
PHP hulp

PHP hulp

24/04/2024 02:46:28
 
Lars Groot

Lars Groot

24/08/2010 22:26:18
Quote Anchor link
Heb je bij dat $_SESSION probeersel ook HELEMAAL bovenaan:
session_start();
staan?

Lars

Toevoeging op 24/08/2010 22:26:20:

Heb je bij dat $_SESSION probeersel ook HELEMAAL bovenaan:
session_start();
staan?

Lars
 
Ewergreen php

ewergreen php

24/08/2010 22:29:53
Quote Anchor link
Zoiets ongeveer had ik geprobeerd met de sessies. Sessies is helaas volledig nieuw voor mij, maar ik zag niet direct een andere oplossing.

Code (php)
PHP script in nieuw venster Selecteer het PHP script
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php
session_start();
    if(!ctype_digit($_POST['NumberOfOptions']) && !isset($_SESSION['views']) ){ //If numerical input was given, don't show the form
        echo "Vul hieronder het aantal antwoorden in:<br />";
        echo "<form action='poll_array.php' method='post'>";
        echo "<input type='text' name='NumberOfOptions'>";
        echo "<input type='submit' value='Maak poll'>";
        echo "</form>";
    }

    else {
        $NumberOfOptions = (int)$_POST['NumberOfOptions'];
        if ($NumberOfOptions <= 1){ //Check for at least 2 answers.
            echo 'Kies minstens twee opties.';
        }

        else {
            $_SESSION['views'] = 1;
            echo '<div id="ShowOptions">';
            echo "<form action='poll_array.php' method='post'>";
            echo "Vul hieronder de antwoorden in:<br />";
            for($count = 1; $count <= $NumberOfOptions; $count++) {//Print desired amount of input options
                echo "Antwoord optie #".$count.": <input name='question[$count]' type='text'><br />";
            }

            echo "<input type='submit' value='Submit optie'>"; //Remember the given options
            echo "</form>";
            echo "</div>";
        }

        
            if(!empty($_POST['questions'])){
            echo "hello";
            }
    }


?>
Gewijzigd op 25/08/2010 11:44:13 door ewergreen php
 



Overzicht Reageren

 
 

Om de gebruiksvriendelijkheid van onze website en diensten te optimaliseren maken wij gebruik van cookies. Deze cookies gebruiken wij voor functionaliteiten, analytische gegevens en marketing doeleinden. U vindt meer informatie in onze privacy statement.