Jump to content
Larry Ullman's Book Forums

AprilSwenby

Members
  • Posts

    85
  • Joined

  • Last visited

Everything posted by AprilSwenby

  1. Okay Jonathon - so I have this now - and no errors! BUT does this meet the requirements? I actually think it might! The instructions say to create a variation on teh make_text_input() function that can create a text input or a password input, depending on upon how the function is called.... Here is my script... function make_text_input($name, $label, $password) { // Begin a paragraph and a label: print '<p><label>' . $label . ': '; // Begin the input: print '<input type="text" name="' . $name . '" size="20" '; // Add the value: if (isset($_POST[$name])) { print ' value="' . htmlspecialchars($_POST[$name]) . '"'; } // Complete the input, the label and the paragraph: print ' /></label></p>'; } // End of make_text_input() function. // Make the form: print '<form action="" method="post">'; // Create some text inputs: make_text_input('first_name', 'First Name', NULL); make_text_input('last_name', 'Last Name', NULL); make_text_input('email', 'Email Address', NULL); make_text_input ('password', 'Enter your password', '$type'); print '<input type="submit" name="submit" value="Register!" /></form>';
  2. This is getting confusing - there are two different pursue questions I am questioning.... The two questions are getting jumbled. Here is what I have for the Pursue # 3. I am to create a variation of the make_text_input() function that can create a text input or a password input depending upon how the function is called. Is this right? Have I met the requirements? <?php // Script 10.3 - Pursue # 3.php /* This script defines and calls a function that creates a sticky text input and creates a text input or a password input */ // This function makes a sticky text input. // This function requires two arguments be passed to it. function make_text_input($name, $label, $size = 20, $type) { // Begin a paragraph and a label: print '<p><label>' . $label . ': '; // Begin the input: print '<input type="text" name="' . $name . '" size="' . $size . '" '; // Add the value: if (isset($_POST[$name])) { print ' value="' . htmlspecialchars($_POST[$name]) . '"'; } if (isset($_POST[$type])) { print ' value="' . htmlspecialchars($_POST[$type]) . '"'; } // Complete the input, the label and the paragraph: print ' /></label></p>'; } // End of make_text_input() function. // Make the form: print '<form action="" method="post">'; // Create some text inputs: make_text_input('first_name', 'First Name'); make_text_input('last_name', 'Last Name', 30); make_text_input('email', 'Email Address', 50); make_text_input ('password', 'Enter your password', 30); print '<input type="submit" name="submit" value="Register!" /></form>'; Obviously this script gives me a whole slew of errors that looks like this: Warning: Missing argument 4 for make_text_input(), called in C:\xampp\htdocs\sticky2.php on line 40 and defined in C:\xampp\htdocs\sticky2.php on line 14 First Name: Notice: Undefined variable: type in C:\xampp\htdocs\sticky2.php on line 27 /> Warning: Missing argument 4 for make_text_input(), called in C:\xampp\htdocs\sticky2.php on line 41 and defined in C:\xampp\htdocs\sticky2.php on line 14 Last Name: Notice: Undefined variable: type in C:\xampp\htdocs\sticky2.php on line 27 /> Warning: Missing argument 4 for make_text_input(), called in C:\xampp\htdocs\sticky2.php on line 42 and defined in C:\xampp\htdocs\sticky2.php on line 14 Email Address: Notice: Undefined variable: type in C:\xampp\htdocs\sticky2.php on line 27 /> Warning: Missing argument 4 for make_text_input(), called in C:\xampp\htdocs\sticky2.php on line 43 and defined in C:\xampp\htdocs\sticky2.php on line 14 Enter your password: Notice: Undefined variable: type in C:\xampp\htdocs\sticky2.php on line 27 /> Now - the second question says to rewrite the make_text_input() function so that it can be told whether to look for an existing value in either $_POST or $_GET... I have no idea how to do that.... Can you give me a little bit more of a hint on the steps to complete this question?
  3. This might help... here is what I have done.... But to be more specific, have I met the requirements? I am supposed to look for an existing value in either $_POST or $_GET... Have I done that? <?php // Script 10.3 - sticky1.php /* This script defines and calls a function that creates a sticky text input. */ // This function makes a sticky text input. // This function requires two arguments be passed to it. function make_text_input($name, $label, $size = 20) { // Begin a paragraph and a label: print '<p><label>' . $label . ': '; // Begin the input: print '<input type="text" name="' . $name . '" size="' . $size . '" '; // Add the value: if (isset($_POST[$name])) { print ' value="' . htmlspecialchars($_POST[$name]) . '"'; } // Complete the input, the label and the paragraph: print ' /></label></p>'; } // End of make_text_input() function. // Make the form: print '<form action="" method="post">'; // Create some text inputs: make_text_input('first_name', 'First Name'); make_text_input('last_name', 'Last Name', 30); make_text_input('email', 'Email Address', 50); make_text_input ('password', 'Enter your password', 30); print '<input type="submit" name="submit" value="Register!" /></form>';
  4. Okay - well that makes sense... But I haven't the foggiest idea on how to do that. I having such a mental block with this one. Seems like I can read code and understand what it is trying to do, but I can't write it.....
  5. I'm Sorry Jonathon - but that didn't help. I am so confused at this point. I think I just need to be pointed in the right direction? Larry do you have anymore input for me?
  6. Hi Larry - thank you for your quick response! I see what you are referring to- so if I understand it correctly then, and if I sue page 269 as an example, I should rewrite line 14 to read function make_text_input(_POST, _GET) then line 36 should read make_text_input ('_POST', '_GET'); I know that's not right and that won't work - but I just can't get the dots to connect in my head. I can understand in English that you want the function to ultimately read what ever is in line 23... Why is writing code so difficult to comprehend? I'm finding that I'm having troubles even knowing "how' to ask you my question....
  7. To complete the requirements for Chapter 10's # 2 pursue question... Do we rewrite the form and submit one that looks like this? if ($_SERVER['REQUEST_METHOD'] == 'GET') { // Check for values: if ( is_numeric($_GET['quantity']) AND is_numeric($_GET['price']) ) { // Call the function and print the results: $total = calculate_total($_GET['quantity'], $_GET['price']); print "<p>Your total comes to $<span style=\"font-weight: bold;\">$total</span>.</p>"; } else { // Inappropriate values entered. print '<p style="color: red;">Please enter a valid quantity and price!</p>'; } } And then change the form method to GET, or is the author looking for something else? Maybe I've missed the whole concept here? Also - for the 3rd question in the pursue - I understand that I need to create a new line item after line 38 called make_text_input('password', 'Password'); But I cannot connect the dots as to what goes above that? I am trying to process this through by looking at page 269. I have a feeling I need to add something in the if function. Can you direct me in the right direction. Sorry for the dumb questions, but this is really above my scope of understanding and I'm trying to put it into a language I do understand! Thanks! April
  8. Well... First of all Dreamweaver is saying that I have an error on line 16 which is my } elseif (isset($_POST['font_size']) { and line 18 which is my } else { and it's also erroring on 25 and 27 which is the } elseif (isset($_POST['font_color']) { and my } else { I can't believe that he script isn't right because I copied it from the previous post. Unless I am missing something? Am I supposed to change my customize.php fil at all? The only file I changed is my view_settings.php fil.e Like I said, I feel like I am in over my head. I really like your book, I am just not comprehending some of these concepts and the order of things .... and the order of the syntax. By not working I mean, When I run the script in the browser, my colors do not change as per the instructions - aren't my font color and my font size suppose to dynamically change? Maybe I didn't understand the instructions, but nothing changes. PHP Version 5.3.5
  9. I too have a the same question (and to be honest, as I started chapter 8, I began to feel out of my league - so I am in severe need of step by step instructions come this chapter until some of these concepts hit home) Here is what I have - my view_settings php file looks like this (which I got help from this forum) and it is not working: <style type="text/css"> body { <?php // Pursue # 9 - Customize rewrite - view_settings.php // Check for a font_size value: if (isset($_COOKIE['font_size'])) { print "\t\tfont-size: " . htmlentities($_COOKIE['font_size']) . ";\n"; } elseif (isset($_POST['font_size']) { print "\t\tfont-size: " . htmlentities($_POST['font_size']) . ";\n"; } else { print "\t\tfont-size: medium;"; } // Check for a font_color value: if (isset($_COOKIE['font_color'])) { print "\t\tcolor: #" . htmlentities($_COOKIE['font_color']) . ";\n"; } elseif (isset($_POST['font_color']) { print "\t\tcolor: #" . htmlentities($_POST['font_color']) . ";\n"; } else { print "\t\tcolor: #000;"; } ?> } </style> </head> <body> <p><a href="customize.php"> Customize Your Settings</a></p> <p><a href="reset.php">Reset your Settings</a></p> <p> Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda Yadda </p> </body> </html> My customize looks like this: <?php // Script 9.1 - Cutomize.php // Handle the form if it has been submitted: if (isset($_POST['font_size'], $_POST['font_color'])) { // Send the cookies: setcookie('font_size', $_POST['font_size'], time()+1000000, '/', '', 0); setcookie('font_color', $_POST['font_color'], time()+1000000, '/', '', 0); //Message to be printed later: $msg = '<p> Your settings have been entered! Click <a href="view_settings.php"> here</a> to see them in action.</p>'; } // End of submitted IF. ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> <title>Customize Your Settings</title> </head> <body> <?php // If the cookies were sent, print a message. if (isset($msg)) { print $msg; } ?> <p>Use this form to set your preferences:</p> <form action="customize.php" method="post"> <select name="font_size"> <option value="">Font Size</option> <option value="xx-small">xx-small</option> <option value="x-small">x-small</option> <option value="small">small</option> <option value="medium">medium</option> <option value="large">large</option> <option value="x-large">x-large</option> <option value="xx-large">xx-large</option> </select> <select name="font_color"> <option value="">Font Color</option> <option value="999">Gray</option> <option value="0c0">Green</option> <option value="00f">Blue</option> <option value="c00">Red</option> <option value="000">Black</option> </select> <input type="submit" name="submit" value="Set My Preferences" /> </form> </body> </html>
×
×
  • Create New...