p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 (http://p2p.wrox.com/forumdisplay.php?f=160)
-   -   Chapter 2 Exercise #5 (http://p2p.wrox.com/showthread.php?t=80678)

yowzer14 August 26th, 2010 12:33 AM

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>



All times are GMT -4. The time now is 05:11 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.