Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

PHP

Misha Karas
Misha Karas
5,636 Points

PHP basics school question

So for a school project i need to make a few tasks. In the binder i got from school its is realy unclear how i should do the next task and i need some help. The question is as follows.

Make a form where the user can input Zip codes, then make sure the zip code is between 8000AA and 8069ZZ and that the input is not empty, use for this the AND operator if this is true echo " regio Zwolle". If the feeld is not empty and it is not in between 8000AA and 8069ZZ echo "niet in de regio Zwolle" if the feeld is empty echo " voer een postcode in".

i hope every one understands my translation i am not that great in english. This is what i got so far

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>02if-extra</title>
    </head>
    <body>
            <form action="02-extra.php" method="post">
                <input type="text" name="postcode" value="">
                <input type="submit" name="submit" value="Click me!">
            </form>
            <?php
                    $postcode1 = "8000AA"
                    $postcode2 = "8069ZZ"

                if (empty($_POST['postcode'])) {
                    echo "Voer een postcode in.";
                } elseif ($_POST['postcode']) { // Here do i need to calculate if the input of the user is inbetween variable $postcode1 and variabel $postcode2.
                    echo "Binnen de regio Zwolle";
                } else {
                    echo "Buiten regio Zwolle";
                }

             ?>
    </body>
</html>

Thanks in advanced for helping me out! All help is apricated!

1 Answer

Misha Karas
Misha Karas
5,636 Points

Guys never mind i got it to work. This code under here did the trick. Still thanks though,

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title>02if-extra</title>
    </head>
    <body>
            <form action="02-extra.php" method="post">
                <input type="text" name="postcode" value="">
                <input type="submit" name="submit" value="Click me!">
            </form>
            <?php
                    $postcode1 = "8000AA";
                    $postcode2 = "8069ZZ";

                if (empty($_POST['postcode'])) {
                    echo "Voer een postcode in.";
                } elseif ($_POST['postcode']  >= $postcode1 && ($_POST['postcode'] <= $postcode2)) {
                    echo "Binnen de regio Zwolle";
                } else {
                    echo "Buiten regio Zwolle";
                }

             ?>
    </body>
</html>