Jump to content

helpmehelpmehelpme

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

Everything posted by helpmehelpmehelpme

  1. okay, it looks like they all work except for the background color and the link color.
  2. i have this example, but im not sure how to do it for the background color and the others, if (isset($_COOKIE['font_color'])) { print "\t\tcolor: #" . htmlentities($_COOKIE['font_color']) . ";\n"; } else { print "\t\tcolor: #000;"; }
  3. it still doesn't work, but could you do an if statement. like if the user selects whatever color from the drop down list, change the styles color or something like that
  4. no errors this time, but it's still not changing the styles on the page. The background is white, it should change when the user selects a color and goes to file3
  5. like this? <style type="text/css"> <!-- These are the styles the session should configure --> a:link {color:#<? $_COOKIE['link_color']; ?>} //Use the variable in the style a:hover {color:#<? $_COOKIE['link_hover_color']; ?>} body {background-color:#<? $_COOKIE['background_color']; ?>} h1 {color:#<? $_COOKIE['header_color']; ?> text-align:center;} </style> it still doesnt change the styles on the page....im confused
  6. sorry, file 2 returned that but when you click click here to see it in action which goes to file3, it says Notice: Undefined index: background_color in C:\xampp\htdocs\xampp\PHP\file3.php on line 10 Notice: Undefined index: link_color in C:\xampp\htdocs\xampp\PHP\file3.php on line 11 Notice: Undefined index: link_hover_color in C:\xampp\htdocs\xampp\PHP\file3.php on line 12 Notice: Undefined index: header_color in C:\xampp\htdocs\xampp\PHP\file3.php on line 13 Welcome to YOUR pretty website Click here to go back and start over! and the original styles are displayed
  7. I tried that instead of it applying the changes to the styles, it prints returns \body: #c00\a:link: #00f Your settings have been updated. Click here to continue. on the page. I don't know, there must be an error somewhere heres the updated code file1.php <?php //Handle the form if it has been submitted: if (isset($_POST['background_color'], $_POST['link_color'], $_POST['link_hover_color'], $_POST['header_color'])){ //send the cookies: setcookie('background_color', $_POST['background_color'], time()+10000000); setcookie('link_color', $_POST['link_color'], time()+10000000); setcookie('link_hover_color', $_POST['link_hover_color'], time()+10000000); setcookie('header_color', $_POST['header_color'], time()+10000000); //Message to be printed later: $msg = '<p>Your settings have been entered! Click <a href="file2.php">here</a> to see them in action.</p>'; } ?> <!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>File1</title> <style type="text/css"> <!-- These are the styles the session (if it exists) should configure --> a:link {color:blue;} a:hover {color:orange;} body {background-color:red} h1 {color:blue; text-align:center;} </style> </head> <body> <?php //if the cookies were sent print a message if (isset($msg)){ print $msg; } ?> <div><p>Please complete this form to configure the appearance of this website:</p> <form action="File2.php" method="post"> <select name="background_color"> <option value="">Background Color</option> <option value="FF6600">Orange</option> <option value="CC00CC">Purple</option> <option value="FFFF00">Yellow</option> <option value="00FF00">Green</option> <option value="FF0066">Pink</option> <option value="000099">Blue</option> </select> <select name="link_color"> <option value="">Link Color</option> <option value="FF6600">Orange</option> <option value="CC00CC">Purple</option> <option value="FFFF00">Yellow</option> <option value="00FF00">Green</option> <option value="FF0066">Pink</option> <option value="000099">Blue</option> </select> <select name="link_hover_color"> <option value="">Link Hover Color</option> <option value="FF6600">Orange</option> <option value="CC00CC">Purple</option> <option value="FFFF00">Yellow</option> <option value="00FF00">Green</option> <option value="FF0066">Pink</option> <option value="000099">Blue</option> </select> <select name="header_color"> <option value="">Header Color</option> <option value="FF6600">Orange</option> <option value="CC00CC">Purple</option> <option value="FFFF00">Yellow</option> <option value="00FF00">Green</option> <option value="FF0066">Pink</option> <option value="000099">Blue</option> </select> <input type="submit" name="submit" value="Configure!" /> </form> </div> </body> </html> file3.php <!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>File3</title> <?php $backgroundcolor = $_COOKIE['background_color']; $linkcolor = $_COOKIE['link_color']; // Define the variable $linkhovercolor = $_COOKIE['link_hover_color']; $headercolor = $_COOKIE['header_color']; ?> <style type="text/css"> <!-- These are the styles the session should configure --> a:link {color:#<?php $linkcolor; ?>} //Use the variable in the style a:hover {color:#<?php $linkhovercolor; ?>} body {background-color:#<?php $backgroudcolor; ?>} h1 {color:#<?php $headercolor; ?> text-align:center;} </style> </head> <body> <div> <h1>Welcome to YOUR pretty website</h1> <a href = "File1.php">Click here</a> to go back and start over!</a> </div> </body> </html>
  8. I'm trying to write a script that allows the user to select their personal settings for the site. They can pick the color of their background, link color, link hover color and the header color. the first file is supposed to use the defaults, blue for the links, orange for the link hover color red for the background and blue for the header. the second file is supposed to configure the cookie variables to store the values entered by the user and the third file i'm supposed to modify the internal stylesheet to utilize the values stored in the session variables. I tried to set each of the values in file two but i think i messed it up. I dont know how to modify the stylesheet to accept and change to the values of the cookies...Please help here are the files file1.php <?php //Handle the form if it has been submitted: if (isset($_POST['background_color'], $_POST['link_color'], $_POST['link_hover_color'], $_POST['header_color'])){ //send the cookies: setcookie('background_color', $_POST['background_color'], time()+10000000); setcookie('link_color', $_POST['link_color'], time()+10000000); setcookie('link_hover_color', $_POST['link_hover_color'], time()+10000000); setcookie('header_color', $_POST['header_color'], time()=10000000); //Message to be printed later: $msg = '<p>Your settings have been entered! Click <a href="file2.php">here</a> to see them in action.</p>'; } ?> <!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>File1</title> <style type="text/css"> <!-- These are the styles the session (if it exists) should configure --> a:link {color:blue;} a:hover {color:orange;} body {background-color:red} h1 {color:blue; text-align:center;} </style> </head> <body> <?php //if the cookies were sent print a message if (isset($msg)){ print $msg; } ?> <div><p>Please complete this form to configure the appearance of this website:</p> <form action="File2.php" method="post"> <select name="background_color"> <option value="">Background Color</option> <option value="FF6600">Orange</option> <option value="CC00CC">Purple</option> <option value="FFFF00">Yellow</option> <option value="00FF00">Green</option> <option value="FF0066">Pink</option> <option value="000099">Blue</option> </select> <select name="link_color"> <option value="">Link Color</option> <option value="FF6600">Orange</option> <option value="CC00CC">Purple</option> <option value="FFFF00">Yellow</option> <option value="00FF00">Green</option> <option value="FF0066">Pink</option> <option value="000099">Blue</option> </select> <select name="link_hover_color"> <option value="">Link Hover Color</option> <option value="FF6600">Orange</option> <option value="CC00CC">Purple</option> <option value="FFFF00">Yellow</option> <option value="00FF00">Green</option> <option value="FF0066">Pink</option> <option value="000099">Blue</option> </select> <select name="header_color"> <option value="">Header Color</option> <option value="FF6600">Orange</option> <option value="CC00CC">Purple</option> <option value="FFFF00">Yellow</option> <option value="00FF00">Green</option> <option value="FF0066">Pink</option> <option value="000099">Blue</option> </select> <input type="submit" name="submit" value="Configure!" /> </form> </div> </body> </html> file2.php <!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>File2</title> </head> <body> <div> <?php include('file1.php'); //check for a background color if (isset($_COOKIE['background_color'])){ print "\body: #" . htmlentities($_COOKIE['background_color']) . ";\n"; }else{ print "\body: #c00"; } //check for a link_color if (isset($_COOKIE['link_color'])){ print "\a:link: #" . htmlentities($_COOKIE['link_color']) . ";\n"; }else{ print "\a:link: #00f"; } //check for a link_hover color: if (isset($_COOKIE['link_hover_color'])){ print "a\:hover: #" . htmlentities($_COOKIE['link_hover_color']) . ";\n"; } //Check for a header color if (isset($_COOKIE['header_color'])){ print "\h1: #" . htmlentities($_COOKIE['header_color']). ";\n"; } ?> Your settings have been updated. <a href="File3.php">Click here</a> to continue. <br /><br /> </div> </body> </html> file3.php <!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>File3</title> <style type="text/css"> <!-- These are the styles the session should configure --> a:link {color:blue;} a:hover {color:orange;} body {background-color:red} h1 {color:blue; text-align:center;} </style> </head> <body> <div> <h1>Welcome to YOUR pretty website</h1> <a href = "File1.php">Click here</a> to go back and start over!</a> </div> </body> </html> I'm pretty sure i did in file2 what i was supposed to do in file3 im totally confused
  9. heres the updated code test1.html <!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>Feedback Form</title> </head> <body> <div><p>Please complete this form to submit your feedback:</p> <form action="test1.php" method="post"> <p>Name: <select name="title"> <option value="Mr.">Mr.</option> <option value="Mrs.">Mrs.</option> <option value="Ms.">Ms.</option> </select> <input type="text" name="name" size="20" /></p> <p>Email Address: <input type="text" name="email" size="20" /></p> <p>Age: <input type="text" name="age" size="20" /></p> <p>Response: This is... <input type="radio" name="response" value="excellent" /> excellent <input type="radio" name="response" value="okay" /> okay <input type="radio" name="response" value="boring" /> boring</p> <p>Comments: <textarea name="comments" rows="3" cols="30"></textarea></p> <input type="submit" name="submit" value="Send My Feedback" /> </form> </div> </body> </html> test1.php <!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>Your Feedback</title> </head> <body> <?php include('test1.html'); $name = $_POST['name']; $age = $_POST['age']; $okay = TRUE; $i = $_POST['age']; if(empty($name)){ echo '<p class="error"> Please enter your name.</p>'; $okay = FALSE; } if (empty($age)){ echo '<p class="error"> Please enter you age.</p>'; $okay = FALSE; } if ($age < 65){ echo '<p>no retirement for you</p>'; } if ($age == 65){ echo '<p> Yay, you can retire</p>'; } if ($age > 65 && $age < 100){ echo '<p>Florida is for me!</p>'; } if ($age > 100){ echo '<p>Good Genes</p>'; } //print users age to 1000 by 3s for($i=$age; $i<1000;$i+3){ echo $age; } ?> </body> </html>
  10. now it prints out the users age, but it won't increment by 3s
  11. okay, now it prints out $age$age$age$age$age$age$age$age$age$age$age$age$age$age$age$age$age$age$age$age$age$age$age infinitely
  12. right, but i keep getting error messages $age Notice: Use of undefined constant i - assumed 'i' in C:\xampp\htdocs\xampp\PHP\test1.php on line 38 $age Notice: Use of undefined constant i - assumed 'i' in C:\xampp\htdocs\xampp\PHP\test1.php on line 38 $age Notice: Use of undefined constant i - assumed 'i' in C:\xampp\htdocs\xampp\PHP\test1.php on line 38 $age Notice: Use of undefined constant i - assumed 'i' in C:\xampp\htdocs\xampp\PHP\test1.php on line 38 $age Notice: Use of undefined constant i - assumed 'i' in C:\xampp\htdocs\xampp\PHP\test1.php on line 38 $age
  13. I have this script that asks the user their name and email address and age and stuff and it checks to see what their age is and outputs a message depending on what age bracket they belong to. I am trying to make a for loop that uses the value the user submitted for their age and output the range of numbers from the users age to 1000 by 3s, i know how the basic for loop works, but i don't know how to do one where you are using a variable for i. if that makes sense. Heres the code that i have. test1.html <!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>Feedback Form</title> </head> <body> <div><p>Please complete this form to submit your feedback:</p> <form action="test1.php" method="post"> <p>Name: <select name="title"> <option value="Mr.">Mr.</option> <option value="Mrs.">Mrs.</option> <option value="Ms.">Ms.</option> </select> <input type="text" name="name" size="20" /></p> <p>Email Address: <input type="text" name="email" size="20" /></p> <p>Age: <input type="text" name="age" size="20" /></p> <p>Response: This is... <input type="radio" name="response" value="excellent" /> excellent <input type="radio" name="response" value="okay" /> okay <input type="radio" name="response" value="boring" /> boring</p> <p>Comments: <textarea name="comments" rows="3" cols="30"></textarea></p> <input type="submit" name="submit" value="Send My Feedback" /> </form> </div> </body> </html> test1.php <!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>Your Feedback</title> </head> <body> <?php include('test1.html'); $name = $_POST['name']; $age = $_POST['age']; $okay = TRUE; if(empty($name)){ echo '<p class="error"> Please enter your name.</p>'; $okay = FALSE; } if (empty($age)){ echo '<p class="error"> Please enter you age.</p>'; $okay = FALSE; } if ($age < 65){ echo '<p>no retirement for you</p>'; } if ($age == 65){ echo '<p> Yay, you can retire</p>'; } if ($age > 65 || $age < 100){ echo '<p>Florida is for me!</p>'; } if ($age > 100){ echo '<p>Good Genes</p>'; } //print users age to 1000 by 3s for($i=$age; $<1000 i+3){ echo '$age'; } ?> </body> </html>
  14. i have this script where the user enters their name and their favorite quotes. It adds their favorite quotes and their names to quotes.txt and prints out their name and their quotes on view_quote.php. I need to use a foreach() loop to print out the name and the quotes, but I'm confused about how to set it up. Here's my files. add_quote.php <!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>Add A Quotation</title> </head> <body> <?php // add_quote.php /* This script displays and handles an HTML form. This script takes text input and stores it in a text file. */ // Identify the file to use: $file = 'quotes.txt'; // Check for a form submission: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form. if ( !empty($_POST['quote']) && ($_POST['quote'] != 'Enter your quotation here.' ) ){ // Need some thing to write. if (is_writable($file)) { // Confirm that the file is writable. file_put_contents($file, $_POST['quote'] . PHP_EOL, FILE_APPEND | LOCK_EX); // Write the data. file_put_contents($file, $_POST['name'] . PHP_EOL, FILE_APPEND | LOCK_EX); // Print a message: print '<p>Your quotation has been stored.</p>'; } else { // Could not open the file. print '<p style="color: red;">Your quotation could not be stored due to a system error.</p>'; } } else { // Failed to enter a quotation. print '<p style="color: red;">Please enter a quotation!</p>'; } } // End of submitted IF. // Leave PHP and display the form: ?> <form action="add_quote.php" method="post"> <p>Name:<input type="text" name="name"/><br /> <textarea name="quote" rows="5" cols="30">Enter your quotation here.</textarea><br /> <input type="submit" name="submit" value="Add This Quote!" /> </form> </body> </html> view_quote.php <!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>View A Quotation</title> </head> <body> <h1>View My Quotes</h1> <?php // view_quote.php /* This script displays and handles an HTML form. This script reads in a file and prints a random line from it. */ // Read the file's contents into an array: $data = file('quotes.txt'); // Count the number of items in the array: $n = count($data); // Pick a random item: $rand = rand(0, ($n - 1)); // Print the quotation: print '<p>' . trim($data[$rand]) . '</p>'; ?> </body> </html> and the quotes.txt file is blank until the user enters their names and quotes. Im trying to get this done kind of quick so any help would be awesome.
  15. okay, i did that, but im still getting the extra letters.
  16. i did that, but it's still giving me the extra f and l letters in addition to the initials. Im stumped..ive been working on this for two days now and i cant seem to figure out where the extra letters are coming from
  17. i have this, but for some reason that i cant figure out it's giving me extra letters. if i enter kelly norton, it outputs fknl or jerry lewis, fjll, here's the code: index.php <!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>Functions!</title> </head> <body> <p>Please enter your first and last name so I can give you your initials.</p> <form action="functions.php" method="post"> <?php for ($i = 0; $i < 5; $i++) { // Maybe do a fieldset to separate each group. print '<legend>Enter Name</legend>'; print('<label for="first_name%d">First Name:</label>', $i); print('<input id="first_name%d" type="text" name="name[][first]" size="20" />', $i); print('<label for="last_name%d">Last Name:</label>', $i); print('<input id="last_name%d" type="text" name="name[][last]" size="20" />', $i); //print '</fieldset>'; } ?> <input type="submit" name="submit" value="Get My Initials" /> </body> </html> functions.php <?php if (isset($_POST['name']) && is_array($_POST['name'])) { foreach ($_POST['name'] AS $fullname) { list($first, $last) = each($fullname); print first_and_last($first, $last); } } function first_and_last($first_name, $last_name ) { return $first_name[0] . '. ' . $last_name[0] . '.'; } //echo first_and_last($_POST['first_name'], $_POST['last_name']); ?>
  18. i need one where the user can enter the names themselves and have it cycle through and print out the initials of all the names the user has entered...
  19. If you had a function that calculated the average of a fixed quantity of numbers, what type of scope issues would you anticipate?
  20. can you do like a loop or something that would let the user enter like 5 other names and have it print out all of the initials?
  21. oh duh, i was thinking you had to do the $_POST up in the function somewhere...thanks for your help..
  22. okay, I have index.php <!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>Functions!</title> </head> <body> <p>Please enter your first and last name so I can give you your initials.</p> <form action="functions.php" method="post"> <p>First Name: <input type="text" name="first_name" size="20" /></p> <p>Last Name: <input type="text" name="last_name" size="20" /></p> <input type="submit" name="submit" value="Get My Initials" /> </form> </body> </html> and function.php <?php function first_and_last($first_name, $last_name ) { return $first_name[0] . '. ' . $last_name[0] . '.'; } ?> if i'm posting $first_name and $last_name from the index.php page to the functions.php page where would I put the $_POST? or how would i write it into the code
×
×
  • 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.