Search the Community
Showing results for tags 'chapter 3'.
-
On page 92, Chapter 3, making sticky forms: In this chapter a form is created with PHP used to create a text field for inputting distance. Code then validates the content to make sure it is present and a number. The form remembers what was entered so that if an error is thrown the previous input is still there. The following code is used to remember the distance entered by the user. <?php if (isset($_POST['distance'])) { echo $_POST['distance']; } ?> The book then remarks that this can be condensed onto one line, i.e. <?php if (isset($_POST['distance'])) echo $_POST['distance']; ?> but that doing so is rarely recommended. In the interests of learning best practice I decided to go with the first option of splitting out the if statement. However, I noticed that this causes issues in the resulting form in that the Distance text field contains large number of extra characters which mean that the is_numeric test always fails. This does not happen when using the if statement in a single line. Given that both syntaxes are supposed to perform the same, this is somewhat puzzling and I wondered if anyone else has encountered it or found an explanation? The full field creation is as follows in both syntaxes: <p>Distance (miles): <input type="text" name="distance" value="<?php if (isset($_POST['distance'])) echo $_POST['distance']; ?> "/></p> <p>Distance (miles): <input type="text" name="distance" value=" <?php if (isset($_POST['distance'])) { echo $_POST['distance']; } ?> "/></p> Libby
-
Greetings to all (and especially you Larry) I'm having difficulties getting the CSS to show and I think there is something wrong with my path to CSS. I like to have things tidy and pretty so I created a subfolder in my www root called "myCMS". FileStructure = myCMS(folder) index.php assets(folder) css(folder) style.css img(folder) logo.png includes(folder) header.html footer.html I get the includes to work and they show when rendering index.html but there is no styling... In header.html I have <link href="assets/css/style.css" rel="stylesheet"> But my greenhord guess is that the path is wrong?? Ideas why CSS wont show? Cheers to all
-
Hi guys, I've been going over chapter 3 today, script 3.10 calculator.php #5 and unless I'm being stupid (most likely) is their an error on line 30 ? Instead of (Larrys code): // Get the cost of those gallons $dollars = $gallons / $ppg; Should it not be: // Get the cost of those gallons $dollars = $gallons * $ppg; After completing the Script and running the results (submitting the form data) using $dollars = $gallons / $ppg; this just did not look right: Total Estimated Cost: The total cost of driving 300 miles, averaging 30 miles per gallon, and paying an average of $3.00 per gallon, is $3.33. If you drive at an average of 65 miles per hour, the trip will take approximately 4.62 hours. Sorry if this has been answered elsewhere (I did check the errata but it contained no reference). But I just thought I'd bring it up, and make sure I'm not having a braindead moment Cheers
- 3 replies
-
- chapter 3
- script 3.10
-
(and 1 more)
Tagged with:
-
I get the following error when I run the sessions.php script which includes the session handler functions line 37 is the call to session_write_close(); What does this mean exactly and how do I rectify it? Incidentally there is a session text file being saved in the tmp directory referred to - its full of data that I don't understand.
-
Hi, Obviously I'm new here, and fairly new to PHP - so far this book has been very helpful and usually easy to follow. I got the 3rd edition from the library and got through Chapter 10 before ordering the 4th edition when it came out. So now I'm just skimming back through the early chapters to see what's different. The calculator script is quite different, and I was wondering about the method of checking if the form has been submitted. The earlier version used a hidden form input and checked if the value was set, the new one checks if $_SERVER['REQUEST_METHOD'] is POST. What's the difference? Is that better or more secure? Does the hidden form input being visible in the HTML source have anything to do with it? BTW, I like your way of showing the tags in blocks. On a couple art websites I'm a member of it's often difficult to tell how tags are going to show up until the piece is posted - and that's important if you're trying to sell something!
- 2 replies
-
- request_method
- form submission
-
(and 2 more)
Tagged with: