Jump to content

Recommended Posts

Hello,

 

I am VERY new to PHP. I have an assignment where we are working on include files. Everything looks okay.... but the contents from the include file are not showing up! Here is the assignment instructions:

 

"The include file that you develop should create a table to display the contents of the

$_REQUEST autoglobal. The table will have two columns showing each name/value pair.

Use the advanced foreach statement syntax from Chapter 2 foreach(array_expression as

$key => $value) to retrieve the index and value of each element of the $_REQUEST array.

Be sure to use the stripslashes() and htmlentities() functions before displaying the text in the

web page. The include file should be named as inc_requestDump.php. Create a second file

named requestDump.php to test the include file."

 

What am I doing wrong?

 

Any help would be greatly appriciated.

inc_requestDump.php

requestDump.php

Link to comment
https://forums.phpfreaks.com/topic/274000-need-help-with-php-code/
Share on other sites

For security reasons, people don't generally download attached files. So, you should place snippets (NOT whole files) within


tags.

 

So, try to narrow down where you think the problem is and show us that code.

 

And then tell your instructor that using $_REQUEST is bad and that they should be teaching their students best practices out of the gate.

Not only that, but using stripslashes () without checking whether or not it's necessary is bad too. In this day and age, with magic_quotes being disabled by default (or removed completely) there is almost no need at all to use stripslashes (). In fact, using it may expose the system to security issues, for an attacker who knows what they're doing.

 

As for what you're problem is:

$FormFields= array("First Name","Last Name","Address","Address 2",
                      "City","State","Zip","Country","Phone","Email");
    foreach ($FormFields as $key=>$value) {

This is not looping through the fields in the $_REQUEST array, it's looping through the $FormFields array you just created. Not sure why you decided to make that array either, to be honest.

 

That said, a good rule of thumb when writing code is to ask yourself "does this line do what I think, and do I really need it?" The first part will help you answer the second part, and if the answer to the second part is "no" then you should remove the offending line. Code that does not bring you one step closer to the end goal, isn't code that should be present in a script. All it does is to waste time, and potentially create problems.

 

As Antoine de Saint-Exupery said it:

Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.