Undefined Index Error

Hi,
I am completely new to PHP and am following this tutorial.

I am 7mins in and my code is exactly identical to his, yet I get an undefined index error. I am using PHP storm

//The form

<html>
<body>
<form action="learnphp.php" method="post">

    <table border ="0">
        <tr>
            <td>Name</td>
            <td align="center"><input type ="text" name ="username" size="30"/></td>
        </tr>

        <tr>
            <td>Address</td>
            <td align="center"><input type = "text" name ="streetaddress" size = "30"/></td>
        </tr>

        <tr>
            <td>City</td>
            <td align = "center"><input type = "text" name ="cityaddress" size = "30"/></td>
        </tr>

        <tr>
            <td colspan="2" align ="center"><input type ="submit" value ="submit"/></td>
        </tr>
    </table>


</form>
</body>
</html>

//The php code

<!--

            You embed PHP code between tags

            A semicolon has to finish every php statement

            Single quotes : Print what is between them and ignore
            escape sequences except for \' and \\

            Double quotes : Print many escape sequences, the values
            for variables, and more

        -->

<html>
            <head>
                <title>Information Gathered</title>
            </head>
    <body>
        <?php
        echo"<p>Data Processed at </p>";
        date_default_timezone_set('UTC');
        /* Echos the date
                h : 12 hr format
                H : 24 hr format
                i : Minutes
                s : Seconds
                u : Microseconds
                a : Lowercase am or pm
                l : Full text for the day
                F : Full text for the month
                j : Day of the month
                S : Suffix for the day st, nd, rd, etc.
                Y : 4 digit year
         */

            echo date('j F Y H:i');
            echo "</p>";

            $userName = $_POST['username'];
            $streetAddress = $_POST['streetaddress'];
            $cityAddress = $_POST['cityaddress'];

            echo $userName . "</br>";
            echo $streetAddress . "</br>";
            echo $cityAddress . "</br>";


        ?>
    </body>
</html>

Notice: Undefined index: username in J:\Private work\web\learnphp.php on line 40

Notice: Undefined index: streetaddress in J:\Private work\web\learnphp.php on line 41

Notice: Undefined index: cityaddress in J:\Private work\web\learnphp.php on line 42

I am thinking that the php code can’t see the form? But they are both in the same folder. Please help so I can continue with the tutorial

To start with, the tutorial looks like crap. Tables haven’t been used for layouts, in a very very very looooooong time. That by itself makes me question the content.

How are you going to the page? You should be loading the form first, and it redirects to the php page when you submit it.

Well it works with xampp when I start the form. But phpstorm is supposed to have a built in debugger…and I realised it doesnt work with phpstorm.

Is there anything I can do? Or should I just use xampp

PHP Storm is an IDE. XAMPP is a server. You need XAMPP in order to do anything with PHP, because it is the server.

The best thing is to do code changes then go to the page in your browser.

Ok thanks

That online tutorial looks goofy in my opinion. I’m in the process of writing a simple blog tutorial using sqlite3 that most php installations have already installed. If yours doesn’t it shouldn’t be hard to convert over to standard MySQL using PDO that is in the script.

Here’s the repository https://github.com/Strider64/php_sandbox and the file is called mysimpleblog.php. I do have to give a big shoutout to JimL who showed me here how to stylize a HTML form with CSS. The guy doing the video is setting up a lot of newbies to fail for 1. One doesn’t learn PHP in one video (Heck I’m constantly learning something new), 2. One should have a firm grasp on HTML/CSS before tacking PHP (or any other development language) in my opinion and 3. Tutorials generally get outdated fast and from my own experiences they don’t always give you the best way of doing it. Heck even my own tutorials are alway involving and could be improved upon by someone else. Everyone writes code differently than others is also another factor. The object is to learn PHP by tutorials and by going to php.net seeing what certain functions do. When I was developing my own calendar in php I was constantly going to php.net and checking out the DateTime function/method. I am now getting pretty good at that function that I don’t need to go to it anymore. I would go to other tutorials who wrote a calendar program using php to see how they did it, while I might not had use their tutorial verbosely I did get a good idea on how to do it.

Sponsor our Newsletter | Privacy Policy | Terms of Service