Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: PHP and MySQL 24-Hour Trainer
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: PHP and MySQL 24-Hour Trainer
This is the forum to discuss the Wrox book PHP and MySQL 24-Hour Trainer by Andrea Tarr ; ISBN: 978-1-1180-6688-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: PHP and MySQL 24-Hour Trainer 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 Search this Thread Display Modes
  #1 (permalink)  
Old April 4th, 2013, 06:30 PM
Registered User
Points: 26, Level: 1
Points: 26, Level: 1 Points: 26, Level: 1 Points: 26, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Leson 6 Php and mysql 24-hour

I'm having trouble with the following code (I'm using eclipse and it gives no errors):

Code:
<?php
 /**
* lesson06z.php 
* 
* @version 		1.2 2011-02-03
* @package		Smithside Auctions
* @copyright	Copyright (c) 2011 Smithisde Auctions
* @licnese		GNU General Public license
* @since		Since Release 1.0
*/ 
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Cp1252">
<title>Post Data</title>
</head>
<form action="lesson06z.php" method="post">
    <label for="username">User Name:</label><br />
    <input type="text" id="username" name="username" /><br />
    <label for="password">Password</label><br />
    <input type="text" name="password" /><br />
    <br />
    <button type="submit">Submit</button>
</form>
<br />
<p> You entered <?php echo $_POST["username"] ?> as the User Name and <?php echo $_POST["password"] ?> as the Password </p>
</body>
</html>
When I run the routine wilth "localhost/php24/lesson06z.php" the blank User Name block and blank Password blocks come up but I also have the following errors:

You entered
Notice: Undefined index: username in C:\Users\chuck\Desktop\Documents\php\xampp\htdocs\ php24\lesson06z.php on line 27
as the User Name and
Notice: Undefined index: password in C:\Users\chuck\Desktop\Documents\php\xampp\htdocs\ php24\lesson06z.php on line 27
as the Password

However, when I fill in the blank fields and transmit, I get the correct response with no errors:

You entered chuck as the User Name and sdkjfjfkaf as the Password

What am I doing wrong?
Reply With Quote
  #2 (permalink)  
Old April 7th, 2013, 01:57 PM
Tarrconsulting's Avatar
Wrox Author
Points: 50, Level: 1
Points: 50, Level: 1 Points: 50, Level: 1 Points: 50, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Nov 2011
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Errata fix

I haven't had much luck getting my errata added to the errata on the website. This is the fix:

Chapter 6
lesson06x.php

The Notice error is happening because the first time you open the file the form hasn't been submitted so there are no GET's defined yet. To get rid of these errors when we need to check first that the GET's are defined. We can do that with the isset() function.

Replace the <p></p> line with this:

Code:
<?php if (isset($_GET["username"]) AND isset($_GET["password"])) : ?>
	<p>You entered <?php echo $_GET["username"] ?> as the User Name and <?php echo $_GET["password"] ?> as the Password.</p>
<?php else: ?>
	<p>Please enter your User Name and Password.</p>
<?php endif; ?>
This was just an example and you'll find as you go on we start adding in more robust features.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
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
Quick Tips for PHP and MySQL 24-Hour Trainer phparrow BOOK: PHP and MySQL 24-Hour Trainer 0 June 13th, 2012 11:47 AM
Chapter 6 php and mysql 24-hour trainer Old Sarge BOOK: PHP and MySQL 24-Hour Trainer 3 April 12th, 2012 08:19 PM
HTML 5 24-Hour Trainer nathan613 BOOK: HTML5 24-Hour Trainer 0 May 23rd, 2011 08:14 PM
HTML 5 24-Hour Trainer nathan613 BOOK: HTML5 24-Hour Trainer 0 May 22nd, 2011 08:02 PM
How to show 24 Hour Time? Edward King Oracle 1 July 31st, 2004 04:44 AM



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


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