View Single Post
  #1 (permalink)  
Old August 26th, 2010, 12:33 AM
yowzer14 yowzer14 is offline
Registered User
 
Join Date: Aug 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Chapter 2 Exercise #5

Does anyone have a sample of the code to complete this exercise.

This is what I have for the form portion
PHP Code:
<?php

if($_POST['pref'] == 'y')
{
    
setcookie('textfont'$_POST['textfont'], time()+60);
    
setcookie('textcolour'$_POST['textcolour'], time()+60);
    
setcookie('fontsize'$_POST['fontsize'], time()+60);
    exit();
}
session_start();
?>
<html>
 <head>
  <title>Title of document</title>
 </head>
 <body>
    <form method="post" action="formattedtext1.php">
        <p>Enter some text to be formatted
            <textarea name="formatme" rows="5" cols="40">Enter some text</textarea>
        </p>
        <p>Text font
            <select name="textfont">
            <option value="Times New Roman" selected>Times New Roman</option>
            <option value="Bookman Old Style">Bookman Old Style</option>
            </select>
        </p>
        <p>Text colour
            <select name="textcolour">
            <option value="red">Red</option>
            <option value="black" selected>Black</option>
            </select>
        </p>
        <p>Font size
            <select name="fontsize">
            <option value="3">3</option>
            <option value="4" selected>4</option>
            </select>
        </p>
        <p>Do you want to save these preferences for the next time you log in?
            <input type="checkbox" name="pref" value="y">
        </p>
        <p>
            <input type="submit" name="Submit" value="Submit">
        </p>
    </form>
 </body>
</html>
and this is what I have for the display portion
PHP Code:
<?php
session_start
();

$_SESSION["formatme"] = $_POST["formatme"];
?>
<html>
 <head>
  <title>Formatted text</title>
 </head>
 <body>
    <?php
        
echo '<font face="';
        echo 
$_COOKIE["textfont"];
        echo 
'" size="';
        echo 
$_COOKIE["fontsize"];
        echo 
'" color="';
        echo 
$_COOKIE["textcolour"];
        echo 
'">';
        echo 
$_SESSION["formatme"];
        echo 
"</font>";
  
?>
 </body>
</html>
The form portion has this error
Code:
Notice: Undefined index: pref in /var/www/Temp1/Chapter2/formatme1.php on line 3
I get this error when I view the page source
Code:
<html>
 <head>
  <title>Formatted text</title>
 </head>
 <body>

	<font face="
Notice: Undefined index: textfont in /var/www/Temp1/Chapter2/formattedtext1.php on line 18
" size="
Notice: Undefined index: fontsize in /var/www/Temp1/Chapter2/formattedtext1.php on line 20
" color="
Notice: Undefined index: textcolour in /var/www/Temp1/Chapter2/formattedtext1.php on line 22
">Enter some text</font> </body>
</html>
Reply With Quote