Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
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>
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

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 02: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 02: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 01:26 PM



All times are GMT -4. The time now is 03:58 AM.


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