Jump to content



Photo

Chapter 3 On Page 64 Related Error Result


  • Please log in to reply
26 replies to this topic

#1 jeffreader

jeffreader

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 18 February 2017 - 4:39 PM

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:

 


  • 0

#2 jeffreader

jeffreader

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 22 February 2017 - 11:02 PM

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>

 


  • 0

#3 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4744 posts
  • LocationState College, PA (USA)

Posted 23 February 2017 - 8:10 PM

Just to confirm, are you actually filling values into the form?


  • 0

#4 Jaepee

Jaepee

    Advanced Member

  • Members
  • PipPipPip
  • 76 posts
  • LocationSan Jose Ca

Posted 23 February 2017 - 11:01 PM

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:


  • 0

#5 jeffreader

jeffreader

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 11 March 2017 - 4:06 PM

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


  • 0

#6 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4744 posts
  • LocationState College, PA (USA)

Posted 13 March 2017 - 11:54 AM

You're being asked to download the form because you're not running the HTML form page through a URL. You need to load that page via http://something. 


  • 0

#7 jeffreader

jeffreader

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 13 March 2017 - 11:00 PM

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.


  • 0

#8 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4744 posts
  • LocationState College, PA (USA)

Posted 14 March 2017 - 9:55 AM

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.


  • 0

#9 jeffreader

jeffreader

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 14 March 2017 - 11:33 PM

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


  • 0

#10 jeffreader

jeffreader

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 15 March 2017 - 10:28 PM

Please delete my post number 9.  I found my error on my Feedback coding.  Your forum - my post does not have a delete button feature.


  • 0

#11 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4744 posts
  • LocationState College, PA (USA)

Posted 17 March 2017 - 7:26 PM

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!


  • 0

#12 jeffreader

jeffreader

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 18 March 2017 - 11:16 AM

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>


  • 0

#13 jeffreader

jeffreader

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 19 March 2017 - 2:01 PM

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.


  • 0

#14 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4744 posts
  • LocationState College, PA (USA)

Posted 20 March 2017 - 2:41 PM

STDOUT stands for "Standard Output":

https://en.wikipedia...ut_.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).


  • 0

#15 jeffreader

jeffreader

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 1 April 2017 - 8:57 PM

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>


  • 0

#16 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4744 posts
  • LocationState College, PA (USA)

Posted 3 April 2017 - 9:05 AM

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


  • 0

#17 jeffreader

jeffreader

    Newbie

  • Members
  • Pip
  • 12 posts

Posted 3 April 2017 - 11:33 AM

No, I typed it on my Firefox browser - http://localhost/pra...andle_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.)


  • 0

#18 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4744 posts
  • LocationState College, PA (USA)

Posted 3 April 2017 - 1:35 PM

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. 


  • 0

#19 zakalkar

zakalkar

    Newbie

  • Members
  • Pip
  • 1 posts

Posted 6 April 2017 - 6:20 AM

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


  • 0

#20 Larry

Larry

    Administrator/Writer

  • Administrators
  • 4744 posts
  • LocationState College, PA (USA)

Posted 10 April 2017 - 10:06 PM

What was the URL when you run the feedback page in the browser? You have to run it through HTTP:// 


  • 0