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

Chapter 3 Pages 59 And 60

Recommended Posts

SWEAR I entered the code for lines 14-17 exactly as in the book:

 

$title = $_POST['title'];
$name = $_POST['name'];
$response = $_POST['response'];
$comments = $_POST['comments'];
 
But the page I got was:
 
Notice: Undefined index: title in C:\xampp\htdocs\tutorialspoint\handle_form.php on line 14

Notice: Undefined index: name in C:\xampp\htdocs\tutorialspoint\handle_form.php on line 15

Notice: Undefined index: response in C:\xampp\htdocs\tutorialspoint\handle_form.php on line 16

Notice: Undefined index: comments in C:\xampp\htdocs\tutorialspoint\handle_form.php on line 17

Thank you, , for your comments.

You stated that you found this example to be '' and added:

 

 

So I tried a suggestion I found online and altered the code like so:

 

$title = isset($_POST['title']) ?$_POST['title'] : 0 ;
$name = isset($_POST['name']) ? $_POST['name'] : '' ;
$response = isset($_POST['response']) ? $_POST['response'] : '' ;
$comments = isset($_POST['comments']) ? $_POST['comments'] : '' ;
 
The page I got was the following:
 

Thank you, 0 , for your comments.

You stated that you found this example to be '' and added:

 

 

Why isn't it working?

 

P.S. Is there a way to attach files to posts as with emails? I've got screenshots of what I did.

 

 

Share this post


Link to post
Share on other sites

Hi, I had the same errors.  After much searching and testing different things this is what ended up working. 

 

In your feedback.html page add this:

 

<form enctype="form-data/multipart" method="POST" action="handle_form.php">

 

After updating and saving the feedback.html page the handle_form.php page now works.  Remember to refresh the feedback.html page and start again before using it.

Edited by Quinn

Share this post


Link to post
Share on other sites

Hmm...thanks for sharing what worked for you, although it'd surprise me if that made a difference, but your mileage may vary. The most important question is whether the form is being submitted with data or not. If there's no data, then it should print those errors (as written at that point in the book). 

Share this post


Link to post
Share on other sites

Hi, I had the same errors.  After much searching and testing different things this is what ended up working. 

 

In your feedback.html page add this:

 

<form enctype="form-data/multipart" method="POST" action="handle_form.php">

 

After updating and saving the feedback.html page the handle_form.php page now works.  Remember to refresh the feedback.html page and start again before using it.

Thanks! That worked!

 

Hmm...thanks for sharing what worked for you, although it'd surprise me if that made a difference, but your mileage may vary. The most important question is whether the form is being submitted with data or not. If there's no data, then it should print those errors (as written at that point in the book). 

I admit I didn't know that I actually had to add "http://" to the URL first. I thought it was already there even if I didn't literally see it in the address bar. BUT even after I did add "http://" it still didn't work. Only after I tried Quinn's suggestion did it work.

Is there a reason why I and Quinn have to do something like this but others don't? Are we using versions of certain software that's too old or something?

Share this post


Link to post
Share on other sites

It's great that it's working that way for you but this is really surprising to me. That enctype is only required when a form also submits file data. What browser are you seeing this in?

Share this post


Link to post
Share on other sites

It's great that it's working that way for you but this is really surprising to me. That enctype is only required when a form also submits file data. What browser are you seeing this in?

 

I'm running all this on Ubuntu Linux 16.04, and used all 3 browsers I have:  Google Chrome, Firefox and Ubuntu's browser.  I ran the pages many times trying different things, and even with the error checking it didn't help much at all, it just didn't work. 

 

After looking around the web and trying stuff (all of which did not work) I thought I'd try enctype="form-data/multipart" after seeing it.  I did not expect it to work, but it did, in all 3 browsers. 

 

By the way I have to use http:// when I'm working with the Ubuntu browser, it won't work without it.

Share this post


Link to post
Share on other sites

Same thing happened to me. If I use $_REQUEST instead of $_POST everything works just fine, though.

 

Adding enctype="form-data/multipart"> makes it work as well. I'm using Safari (on MacOS High Sierra)

Share this post


Link to post
Share on other sites

It's great that it's working that way for you but this is really surprising to me. That enctype is only required when a form also submits file data. What browser are you seeing this in?

I used Chrome.

Share this post


Link to post
Share on other sites

Sorry I don't have a better answer for y'all, but this has really surprised me. I'd not seen it before. Although to be clear again, it should matter whether form data is being submitted or not (i.e., you shouldn't need the enctype if you're submitting the form). Also, over time you'll learn how to only refer to form values if they have values, which is what really matters. 

 

Thanks for sharing the feedback!

Share this post


Link to post
Share on other sites

Exactly the same for me!! It's been driving me mad until I found this thread and tried the solution mentioned by Quinn and now it works 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...