guayaquil Posted August 18, 2006 Share Posted August 18, 2006 I recently bought [i]PHP 5/MySQL Programming for the absolute beginner,[/i] because I am. I have installed PHP 5.1.4 on my Mac OS X running Apache 1.3 and it works. When I call the info, the info page shows up. However, when I try any of the scripts from the book, they don't work. So is there a version conflct? or something about the author's syntax that's wrong? Here is the code as I use it:<html><head><title>Hi User</title></head><body><h1>Hi User</h1><?if (empty($username)) { print <<<HERE <form> Please enter your name: <input type = "text" name = "username"><br> <input type = "submit"> </form>HERE;} else { print "<h3>Hi there, $username!</h3>";} //end?></body></html>If it is really apparent to you, then I apologize. But I am only beginning and it's frustrating if I can't even use the code in a book for beginners. help. This is what I get:[img]http://www.el-cordovez.com/result.gif[/img] Quote Link to comment https://forums.phpfreaks.com/topic/17927-scripts-from-my-book-dont-work-why/ Share on other sites More sharing options...
Cook Posted August 18, 2006 Share Posted August 18, 2006 That's because the script in your book relies on REGISTER_GLOBALS being turned on, when very likely your csetup has it off (default setting of PHP nowadays).Use $_REQUEST['username'] instead of just $username and it should work better.I used $_REQUEST because I don't remember if the default method for a form is GET or POST, so $_REQUEST will work either way. But better would be to specify the method in the <form> tag:print <<<HERE<form name="myform" method="post" action="$_SERVER['PHP_SELF']">(...)Then you can use $_POST['username']. Quote Link to comment https://forums.phpfreaks.com/topic/17927-scripts-from-my-book-dont-work-why/#findComment-76672 Share on other sites More sharing options...
guayaquil Posted August 18, 2006 Author Share Posted August 18, 2006 Thanks cook, but since I am going to be using so many scripts from this book, shouldn't I just turn on Register_Globals? Quote Link to comment https://forums.phpfreaks.com/topic/17927-scripts-from-my-book-dont-work-why/#findComment-76728 Share on other sites More sharing options...
AndyB Posted August 18, 2006 Share Posted August 18, 2006 [quote author=guayaquil link=topic=104727.msg417960#msg417960 date=1155908601]Thanks cook, but since I am going to be using so many scripts from this book, shouldn't I just turn on Register_Globals?[/quote]No. You should probably throw away the outdated book :)Seriously - program properly rather than including a potential security problem. Register_globals is set as default OFF for very good reasons. Quote Link to comment https://forums.phpfreaks.com/topic/17927-scripts-from-my-book-dont-work-why/#findComment-76732 Share on other sites More sharing options...
guayaquil Posted August 18, 2006 Author Share Posted August 18, 2006 how can it be updated the title says PHP 5. Quote Link to comment https://forums.phpfreaks.com/topic/17927-scripts-from-my-book-dont-work-why/#findComment-76760 Share on other sites More sharing options...
AndyB Posted August 18, 2006 Share Posted August 18, 2006 [quote author=guayaquil link=topic=104727.msg417995#msg417995 date=1155911271]how can it be updated the title says PHP 5.[/quote]That's a question for the authors. register_globals set to OFF has been the default setting in php for quite a long time. Sounds like an old book with a new cover and a few php5 functions thrown in. Quote Link to comment https://forums.phpfreaks.com/topic/17927-scripts-from-my-book-dont-work-why/#findComment-76762 Share on other sites More sharing options...
guayaquil Posted August 18, 2006 Author Share Posted August 18, 2006 NOOOOO! don't tell me I wasted €31 on an outdated book. So it's the difinitely the REGISTER_GLOBALS? the issue? Bummer. This is not very encouraging. Who knows what else would be outdated in the book. Is there a reference for updated tags/comands, etc. for PHP 5? Quote Link to comment https://forums.phpfreaks.com/topic/17927-scripts-from-my-book-dont-work-why/#findComment-76783 Share on other sites More sharing options...
AndyB Posted August 19, 2006 Share Posted August 19, 2006 [quote author=guayaquil link=topic=104727.msg418018#msg418018 date=1155913945]Is there a reference for updated tags/comands, etc. for PHP 5?[/quote]You bet - the online manual at www.php.net Quote Link to comment https://forums.phpfreaks.com/topic/17927-scripts-from-my-book-dont-work-why/#findComment-77073 Share on other sites More sharing options...
.josh Posted August 27, 2006 Share Posted August 27, 2006 ... and this is why I went for Php in easy steps, instead of some really thick book. it cost me 10 bucks, showed me the basics, and from there, it was the online manual. Quote Link to comment https://forums.phpfreaks.com/topic/17927-scripts-from-my-book-dont-work-why/#findComment-81034 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.