Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
jeffreader

Chapter 3 On Page 64 Related Error Result

Recommended Posts

I have an iMac OS 10.12.3 and FireFox browser 51.0.1.  I also use a CodeReader 2.2.2.  I also run on an XAMPP 7.0.13-1 which I turned on the "MySQL Database and Apache Web Server" only.  Now, I am learning from your book as a beginner.

 

HTML Forms and PHP on Chapter 3 and page 64.

 

I submitted my feedback_form.php on the browser - page 64 and my result showed up like this.  How can I fix this problem?

 

Notice: Undefined index: title in /Applications/XAMPP/xamppfiles/htdocs/practice /handle_form.php on line 16

Notice: Undefined index: name in /Applications/XAMPP/xamppfiles/htdocs/practice /handle_form.php on line 17

Notice: Undefined index: response in /Applications/XAMPP/xamppfiles/htdocs/practice /handle_form.php on line 18

Notice: Undefined index: comments in /Applications/XAMPP/xamppfiles/htdocs/practice /handle_form.php on line 19

Thank you, , for your comments.
You stated that you found this example to be '' and added:

 

Share this post


Link to post
Share on other sites

On page 59, this is exact what I wrote down on my CodeRunner and saved the "handle_form.php."  This is what happened above the previous comment that has the errors.   I also wrote down the exact code on feedback.html that came out fine which is on page 56.  I don't understand the errors for this handle_form.php.  Larry, Can you help me with that problem?

 

This is "handle_form.php":

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charest="utf-8">
    <title>Feedback Form</title>
</head>
<body>
    <?php // Script 3.3 handle_form.php
    
    // This page receives the data from feedback.html.
    // It will receive: title, name, email, response, comments, and submit in $_POST.
    
    // Create shorthand versions of the variables:
        $title = $_POST['title'];
        $name = $_POST['name'];
        $response = $_POST['response'];
        $comments = $_POST['comments'];
        
    // Print the received data:
        print "<p>Thank you, $title $name, for your comments.</p>
        <p>You stated that you found this example to be '$response' and added:<br>$comments</p>";    
                
    ?>    
</body>
</html>

 

-------------------------------------------------------

-------------------------------------------------------

 

This is a "feedback.html":

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charest="utf-8">
    <title>Feedback Form</title>
</head>
<body>
    <!-- Script 3.2 - feedback.html -->
    <div><p>Please complete this form to submit your feedback:</p>
    
    <form action="handle_form.php" method="post">
    
        <p>Name: <select name="title" required>
        <option value="Mr.">Mr.</option>
        <option value="Mrs.">Mrs.</option>
        <option value="Ms.">Ms.</option>
        </select> <input type="text" name="name" size="20" required></p>
        
        <p>Email Address: <input type="email" name="email" size="20" required></p>
        
        <p>Response: This is...
        <input type="radio" name="response" value="excellent" required> excellent
        <input type="radio" name="response" value="okay"> okay
        <input type="radio" name="response" value="boring"> boring</p>
            
        <p>Comments: <textarea name="comments" row="3" cols="30" required></textarea></p>
        
        <input type="submit" name="submit" value="Send My Feedback">
        
    </form>
    </div>
</body>
</html>

 

Share this post


Link to post
Share on other sites

Notice: Undefined index

 

This notice appears when you (or your PHP script) atempts to access an undefined index of an array. You can avoid these notices by,  checking with your code to see if the index exists before you access it. For this you can use 

isset()

or 

array_key_exists()

Note that theses notices appear often when working with $_POST, $_GET or $_SESSION. It is good practice to make sure a variable exists and is set before you use it. 

 

Happy Coding!

 

jp :rolleyes:

Share this post


Link to post
Share on other sites

I finally signed a hosting service in order for you to see my two images that I wanted to show you.  Here is the link:

 

http://brioservices.com (only two images on this link)

 

The second picture that I don't understand why it asked me to download the handle_form.php.  My book does not say about the download.

 

I do not feel that I want to skip the chapter until it solves this problem first.  I am sorry I have not read about the isset() and array_key_exits() yet because I am in the chapter 3 this time.  I am currently use my CodeRunner to edit it.  Any idea how to prevent this asking for the download?  http://brioservices.com

Share this post


Link to post
Share on other sites

Hello Larry,

 

First of all, I have an issue with two directories on my iMac.  I created two folders which are "practice" and "My program files." 

 

Do you think that the XAMPP 7.0.13-1 confused with these directories?  ...My XAMPP runs MySQL Database and Apaches Web Server but not ProFTPD.

 

My friend from out of state told me that I put "practice" files in the Applications/XAMPP/xamppfiles/htdocs/practice.  Is that normal?

 

I put all original files in "My program files" folder because of your scripts such as Script 1.5 to Script 3.4... that I do not want them to be override.

 

I do not have your email address but remember that I bought your book.

Share this post


Link to post
Share on other sites

I don't think XAMPP is confused. There's a setting in XAMPP that says where the web root directory is, which is  probably /Applications/XAMPP/xamppfiles/htdocs. The URL http://localhost should point there. So if you put something in /Applications/XAMPP/xamppfiles/htdocs/practice, that URL would be http://localhost/practice

 

It's absolutely fine to use subfolders, but don't use anything in the name of the subfolders that couldn't go in a URL, like spaces.

Share this post


Link to post
Share on other sites

On page 61 and 64.  I created two files for Script 3.3 and 3.4.

 

My original result showed an error for Script 3.3 - The error stated: Undefined index... /handle_form.php on line 17.   It is almost perfect result.

 

So, I created the Script 3.4 below of two images - "2nd result with deleted code lines."

The Script 3.4 looks perfect because I removed two code lines that eliminated the errors.  However, I realized that the ini_set is supposed to show me the problem first.  What is the problem or what did I missed in the coding?

 

Please look at the two codings:  http://brioservices.com/index2.html

Share this post


Link to post
Share on other sites

No, there is no delete post option as I prefer to see what the solutions are to the questions that get raised. Could you kindly share what the solution was that you found? Thanks!

Share this post


Link to post
Share on other sites

Oh well.  I forgot to add " = " between name and "comments on line 28 (feedback.html) which is on page 51.  This is how I get so mad because it does not tell me the specific error.  I wasted my time to figure it out.

 

I looked up my phpinfo.php...

"display_errors => STDOUT => STDOUT"  I have no idea what does that mean.  I thought that it would say  on or off  (See page 63).

 

----

 

I am currently on page 70 - it does not show up a bold name.  It showed up a normal text. What did I missed probably on line 22?

 

Also, I am curious about the Greeting!  Is it supposed to show up another bold Greeting! ?

 

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Greetings!</title>
        <style type="text/css">
        .bold {
            font-weight: bolder;
        }
        </style>
    </head>
    <body>
    <?php // Script 3.7 - hello.php
    
    ini_set('display_errors', 1); // Let me learn my mistakes!
    error_reporting(E_ALL); // Show all possible problems!
    
    // This page should receive a name value in the URL.
    
    // Say "Hello":
        $name = $_GET['name'];
        print "<p>Hello, <span class=\"bold\">$name</span>!</p>";
    ?>
    </body>
</html>

Share this post


Link to post
Share on other sites

Also, how can I turn on the display_errors on my iMac (macOS Sierra)?    If I want to turn it off, what should I do next?  Does it has to do with the Terminal?  I am not familiar with the Terminal app.

Share this post


Link to post
Share on other sites

STDOUT stands for "Standard Output":

https://en.wikipedia.org/wiki/Standard_streams#Standard_output_.28stdout.29

 

If you look in the appendix, you'll see how to configure your PHP installation. It does require the Terminal, so you may want to also look online for the basics of using the Teriminal on Macs. 

 

As for the bold issue, I'd start by checking the source code of the page in the browser. It looks right to me as is (i.e., that it should be in bold).

Share this post


Link to post
Share on other sites

On page 102 - Chapter 5, I submitted this handle_post.php and I get the error immediately.   I do not know where is the problem in my source file.

 

localhost/practice/handle_post.php

Notice: Undefined index: first_name in /Applications/XAMPP/xamppfiles/htdocs/practice/handle_post.php on line 13

Notice: Undefined index: last_name in /Applications/XAMPP/xamppfiles/htdocs/practice/handle_post.php on line 14

Notice: Undefined index: posting in /Applications/XAMPP/xamppfiles/htdocs/practice/handle_post.php on line 15
Thank you, , for your posting:

 

 

 

Here is my source: handle_post.php.

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Forum Posting</title>
</head>
<body>

<?php // Script 5.3 - handling_post.php #2
/* This script receives five values from posting.html: first_name, last_name, email, posting, submit */

// Get the values from the $_POST array:
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$posting = nl2br($_POST['posting'], false);

// Create a full name variable:
$name = $first_name . ' ' . $last_name;

// Print a message:
print "<div>Thank you, $name, for your posting:
<p>$posting</p></div>";

?>
</body>
</html>

 

 

 

 

In case you want to see this one for Forum Posting which is no problem in the previous page.

 

posting.html:

 

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Forum Posting</title>
</head>
<body>
<!-- Script 5.1 - posting.html -->
<div><p>Please complete this form to submit your posting:</p>

<form action="handle_post.php" method="post">

    <p>First Name: <input type="text" name="first_name" size="20"</p>

    <p>Last Name: <input type="text" name="last_name" size="20"</p>

    <p>Email Address: <input type="text" name="email" name="email" size="30"</p>

    <p>Posting: <textarea name="posting" rows="9" cols="30"> </textarea></p>

    <input type="submit" name="submit" value="Send My Posting">
    
</form>
</div>
</body>
</html>

Share this post


Link to post
Share on other sites

Just to confirm, you are actually filling out the form--providing all those values--and yet you still see those error messages?

Share this post


Link to post
Share on other sites

No, I typed it on my Firefox browser - http://localhost/practice/handle_post.php"as long as XAMPP is running.  Then I entered this address and came up the statement errors on the browser - without seeing the form.

 

On Script 5.1 was fine which is on page 94 because I see the form on my browser.  Also on page 99, it was fine for both A and B in the pictures.  On page 102, this is a problem.  Maybe, there are two problems on line 17 and 20.

 

(I saved the handle_post file for PHP and posting file for HTML.)

Share this post


Link to post
Share on other sites

Okay, that's totally fine and to be expected if you run the handle_post.php script directly (as opposed to using the form). If you keep reading, you'll learn more about what's going on. 

Share this post


Link to post
Share on other sites

On page 59, this is exact what I wrote down on my CodeRunner and saved the "handle_form.php."  This is what happened above the previous comment that has the errors.   I also wrote down the exact code on feedback.html that came out fine which is on page 56.  I don't understand the errors for this handle_form.php.  Larry, Can you help me with that problem?

 

This is "handle_form.php":

 

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charest="utf-8">

    <title>Feedback Form</title>

</head>

<body>

    <?php // Script 3.3 handle_form.php

    

    // This page receives the data from feedback.html.

    // It will receive: title, name, email, response, comments, and submit in $_POST.

    

    // Create shorthand versions of the variables:

        $title = $_POST['title'];

        $name = $_POST['name'];

        $response = $_POST['response'];

        $comments = $_POST['comments'];

        

    // Print the received data:

        print "<p>Thank you, $title $name, for your comments.</p>

        <p>You stated that you found this example to be '$response' and added:<br>$comments</p>";    

                

    ?>    

</body>

</html>

 

-------------------------------------------------------

-------------------------------------------------------

 

This is a "feedback.html":

 

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charest="utf-8">

    <title>Feedback Form</title>

</head>

<body>

    <!-- Script 3.2 - feedback.html -->

    <div><p>Please complete this form to submit your feedback:</p>

    

    <form action="handle_form.php" method="post">

    

        <p>Name: <select name="title" required>

        <option value="Mr.">Mr.</option>

        <option value="Mrs.">Mrs.</option>

        <option value="Ms.">Ms.</option>

        </select> <input type="text" name="name" size="20" required></p>

        

        <p>Email Address: <input type="email" name="email" size="20" required></p>

        

        <p>Response: This is...

        <input type="radio" name="response" value="excellent" required> excellent

        <input type="radio" name="response" value="okay"> okay

        <input type="radio" name="response" value="boring"> boring</p>

            

        <p>Comments: <textarea name="comments" row="3" cols="30" required></textarea></p>

        

        <input type="submit" name="submit" value="Send My Feedback">

        

    </form>

    </div>

</body>

</html>

Hello Mr. Larry .... also my browser trying to download the handling file. I played the feedback file from the browser

Share this post


Link to post
Share on other sites

On page 128, Chapter 6:

 

I am lost.  Please rephrase it with plain English for me.  I rather to wait to hear from you before I put that program on my CodeRunner.

Edited by jeffreader

Share this post


Link to post
Share on other sites

Could you elaborate on what you're lost on and what you'd like me to rephrase? 

I can't fresh my mind.  The var1 to var3 have different and also empty().  It is same thing for isset(). 

 

Actually, I thought that there is only one var that something to clear out for one example but it has three examples (i.e. var1, var2, var3).

I am not sure why do I have to know about them.

Share this post


Link to post
Share on other sites

So the examples are just trying to demonstrate what it means to be "set", "empty", and "numeric" and uses a couple of different values--represented by variables--to do so. 

Share this post


Link to post
Share on other sites

Every time I hit "send my feedback" button I get this. 

 

<!DOCTYPE html>
<html lang="en">
<head>
<meta charest="utf-8">
<title>Feedback Form</title>
</head>
<body>
<?php // Script 3.3 handle_form.php

// This page receives the data from feedback.html.
// It will receive: title, name, email, response, comments, and submit in $_POST.

// Create shorthand versions of the variables:
$title = $_POST['title'];
$name = $_POST['name'];
$response = $_POST['response'];
$comments = $_POST['comments'];

// Print the received data:
print "<p>Thank you, $title $name, for your comments.</p>
<p>You stated that you found this example to be '$response' and added:<br>$comments</p>";

?>
</body>
</html>

Edited by lorne

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×