zazu42 Posted February 4, 2013 Share Posted February 4, 2013 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 Quote Link to comment https://forums.phpfreaks.com/topic/274000-need-help-with-php-code/ Share on other sites More sharing options...
KevinM1 Posted February 4, 2013 Share Posted February 4, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274000-need-help-with-php-code/#findComment-1409983 Share on other sites More sharing options...
Christian F. Posted February 4, 2013 Share Posted February 4, 2013 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. Quote Link to comment https://forums.phpfreaks.com/topic/274000-need-help-with-php-code/#findComment-1410014 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.