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 PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6
This is the forum to discuss the Wrox book Beginning PHP, Apache, MySQLWeb Development by Michael K. Glass, Yann Le Scouarnec, Elizabeth Naramore, Gary Mailer, Jeremy Stolz, Jason Gerner; ISBN: 9780764557446
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 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 August 8th, 2004, 02:21 PM
Registered User
 
Join Date: Aug 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Ch 2 pg 70: links throw error

I've completed the code for the "Try It Out" sections up until page 70, and everything had been working fine. After logging in, it takes me to the "movie1.php" page, but then, when I click on the links, it shows me the error (ie "else" response) from my moviesite.php file. I'm guessing that the variables aren't being passed from the login, but I don't know why. I changed some of the text and the button value because I get called a loser enough already, but haven't touched the variables.

Here's the code I have:

LOGIN.PHP

<?php
session_unset();

?>
<html>
<head>
<title>Please Login</title>
</head>

<body>
<?php include "header.php"; ?>
<form method="post" action="http://localhost/movie1.php">
<p>Enter your username:
    <input type="text" name="user">
</p>
<p>Enter your password:
<input type="password" name="pass">
</p>
<p>
<input type="submit" name="Submit" value="Am I Wrong?">
</p>
</form>
</body>
</html>



MOVIE1.PHP

<?php
    session_start();
    $_SESSION['username']=$_POST['user'];
    $_SESSION['userpass']=$_POST['pass'];
    $_SESSION['authuser']=0;

    //Check username and password information
        if (($_SESSION['username']=='Joe') AND
            ($_SESSION['userpass']=='12345'))
        {
        $_SESSION['authuser']=1;
        }
        else
        {
        echo "Try again, dude...";
        exit();
        }
?>
<html>
<head>
<title>Find My Favorite Movie!</title>
</head>
<body>
<?php include "header.php"; ?>
<?php
    $myfavmovie=urlencode("Life of Brian");
    echo "<a href='http://localhost/moviesite.php?favmovie=$myfavmovie'>";
    echo "Click here to see information about my favorite movie!";
    echo "</a>";
    echo "<br>";
    echo "<a href='http://localhost/moviesite.php?movienum=5'>";
    echo "Click here to see my top 5 movies!";
    echo "</a>";
    echo "<br>";
    echo "<a href='http://localhost/moviesite.php?movienum=10'>";
    echo "Click here to see my top 10 movies!";
    echo "</a>";
?>
</body>
</html>



MOVIESITE.PHP

<?php
session_start();
//check to see if user has logged in with a valid password
    if ($_SESSION['authuser']!=1) {
    echo "Sorry, but you don't have permission to view this page, man!";
    exit();
    }
?>
<html>
<head>
<title>My Movie Site - <?php echo $_REQUEST['favmovie'] ?></title>
</head>

<body>
<?php include "header.php"; ?>
<?php
function listmovies_1()
{
    echo "1. Life of Brian<br>";
    echo "2. Stripes<br>";
    echo "3. Office Space<br>";
    echo "4. MP and Holy Grail<br>";
    echo "5. Matrix, The<br>";
}

function listmovies_2()
{
    echo "6. Terminator 3<br>";
    echo "7. Star Wars<br>";
    echo "8. Close Encounters<br>";
    echo "9. Sixteen Candles<br>";
    echo "10. Caddyshack<br>";
}

if (ISSET($_REQUEST['favmovie'])) {
    echo "Welcome to our site, ";
    echo $_SESSION['username'];
    echo "! <br>";
    echo "My favorite movie is ";
    echo $_REQUEST['favmovie'];
    echo "<br>";
    $movierate=5;
    echo "My movie rating for this movie is: ";
    echo $movierate;
    }
    else {
        echo "My top ";
        echo $_REQUEST['movienum'];
        echo " movies are:";
        echo "<br>";

        listmovies_1();
        If ($_REQUEST['movienum'] == 10) listmovies_2();
    }
?>
</body>
</html>
Reply With Quote
  #2 (permalink)  
Old August 9th, 2004, 10:30 AM
Friend of Wrox
 
Join Date: Jun 2004
Location: Fairfield, Iowa, USA.
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Subgenius, I did copie the code from your posting, run it and worked. The only thing that I had to change is the url that you use on your links. Don't really understand why you are using absolute url but I just deleted whatever came before the name(relative url) because I had all the files on the same folder. Whenever you link to another file it will look in the folder where the file from the page you are linking from resides, so there is no need for absolute url. I think the error might be because your files are not all on the same folder. Like I said I just changed the urls on what you posted and it worked as intended.

Christian

Reply With Quote
  #3 (permalink)  
Old August 16th, 2004, 04:22 AM
Authorized User
 
Join Date: Jul 2004
Location: Las Vegas, NV, USA.
Posts: 29
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Ok, first what exactly is the error? Is it telling you that you don't have permission to view the page? If so that is a cookie problem.

If you have your browser properly locked down you will have to add 'localhost' as a site that can set cookies.

Are you running firewall or a program that blocks cookies, or scripts, or what have you? That is most likely your problem.

Reply With Quote
  #4 (permalink)  
Old August 16th, 2004, 04:20 PM
Registered User
 
Join Date: Aug 2004
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I actually just figured out the problem last night. Prior to starting this book, I had installed PHP following the recommendations of the authors from another book that I stopped reading because it had too many errors. When I started this book I figured I was all set, and just jumped right in without checking the settings for Apache and PHP. To make a long story short, the problem was that I needed to create a folder to store my session data, and change the php.ini file's session.save_path path to point to my session folder. So after a week of frustration, I figured it out.

If the authors are reading, I would recommend that they emphasize that readers need to create a tmp/sessions folder in c:/php. They do mention it, but it's buried in a list of variables contained in the php.ini file, and they introduce that section as something to look over after you're more comfortable with PHP. There's also a slew of minors errors in the code. If Wrox expects its readers to shell out $40-$50 for a book, the least they should do is look over the code more closely.
Reply With Quote
  #5 (permalink)  
Old August 16th, 2004, 05:26 PM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Well, to speak out in defense of the authors, some of the errors in this book were caused by less than tech-savvy editors, for instance the $e-mail variable and e-mail SQL fields containing a dash. Wrox requires that email be spelled with a dash, PHP variables forbid it. Do a global search and replace on all instances of email with e-mail, and you find the unexpected side effect of the code getting broken too.

When people set out to write a tech book, often times they have fantastic visions of how to present the content effectively, for instance, how to follow commonly accepted coding practices, using standards markup, etc. Often times the editors have a part to play in why those areas aren't nearly as good as they could be. For instance, fear that people learning PHP won't understand XHTML and CSS, hence use of very old, outdated markup. Or fear of making the manuscript significantly longer by putting in error reporting everywhere you possibly can. Its what you do in the real world, but an area where corners are sometimes cut when you're teaching someone how to write a new language.

Technical books are also forced to be done under very tight deadlines, since technical material is timely and quick to become outdated. Sometimes that involves putting multiple authors on a project, and sometimes those authors don't even collaborate together on the manuscipt! Each is given a few chapters to write and they write them.

Put all of this together and you get a less than perfect manuscript. You should use a technical book to become comfortable with writing a language and to aquire the tools necessary to maintain and expand your knowledge of that language, e.g. be able to visit php.net and actually understand the documentation provided there. Start answering questions in forums like this one. Don't know the answer, find it on Google, and that too helps you to aquire more knowledge and build your ability to troubleshoot bugs, write your own testcases, etc.

My .02 anyway :-)

Regards,
Rich

--
[http://www.smilingsouls.net]
[http://pear.php.net/Mail_IMAP] A PHP/C-Client/PEAR solution for webmail
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
asp.net 2.0 (VB) error try it out ch 5 pg 160 rdixon2005 BOOK: Beginning ASP.NET 2.0 BOOK VB ISBN: 978-0-7645-8850-1; C# ISBN: 978-0-470-04258-8 0 January 10th, 2008 02:37 PM
CH 3 pg 96 Question mririe BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 8 August 25th, 2004 04:17 AM
CH 5 pg 160 wadesmart BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 8 November 12th, 2003 11:23 PM
CH 4 Pg 143 HTMLSpecialChars wadesmart BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 November 3rd, 2003 02:29 PM
CH 3 pg 76 wadesmart BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 2 October 26th, 2003 08:46 PM



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


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