p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: PHP and MySQL 24-Hour Trainer (http://p2p.wrox.com/forumdisplay.php?f=659)
-   -   Leson 6 Php and mysql 24-hour (http://p2p.wrox.com/showthread.php?t=89777)

Old Sarge April 4th, 2013 06:30 PM

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?

Tarrconsulting April 7th, 2013 01:57 PM

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.


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

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