Wrox Programmer Forums
|
BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0
This is the forum to discuss the Wrox book Beginning PHP5, Apache, and MySQL Web Development by Elizabeth Naramore, Jason Gerner, Yann Le Scouarnec, Jeremy Stolz, Michael K. Glass; ISBN: 9780764579660
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP5, Apache, and MySQL Web Development ISBN: 978-0-7645-7966-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 26th, 2010, 12:33 AM
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>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 5 Exercise 2 diango BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 4 February 1st, 2011 03:24 PM
Chapter 8 exercise 1 Will BOOK: Beginning C# 3.0 : An Introduction to Object Oriented Programming ISBN: 978-0-470-26129-3 2 March 2nd, 2010 03:26 PM
Chapter 3 - Exercise 3 AndyN BOOK: Beginning Cryptography with Java 3 August 16th, 2006 03:09 PM
Chapter 5 - Exercise 1 scgtman BOOK: Beginning Visual Basic 2005 Databases ISBN: 978-0-7645-8894-5 3 May 16th, 2006 08:10 PM
Chapter 8, Exercise 4 cjo BOOK: Beginning ASP.NET 1.0 0 November 3rd, 2003 02:26 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.