extremeshannon Posted January 1, 2012 Share Posted January 1, 2012 This is a simple php program and it doesn't work the way it is suppose to. The page see's $username as empty. I have not been able to fix it. I am reading a book and following all the code but anything passing variables to another page or with in the page is not working for me. any help would be great. <html> <head> <title>Hi User</title> </head> <body> <h1>Hi User</h1> <? if (empty($userName)){ print <<<HERE <form> please enter you name: <input type = “text” name = “userName”> <br> <input type = "submit"> </form> HERE; }else{ print "<h3>Hi There, $userName !</h3>"; }//end ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/254167-newbie-help-please/ Share on other sites More sharing options...
Pikachu2000 Posted January 1, 2012 Share Posted January 1, 2012 First thing, use full opening tag syntax <?php, rather than the short <? syntax. Second is the quotes in the markup are curly, or smart quotes. They need to be straight quotes. Make those changes, and see if there's any difference. Quote Link to comment https://forums.phpfreaks.com/topic/254167-newbie-help-please/#findComment-1303092 Share on other sites More sharing options...
extremeshannon Posted January 1, 2012 Author Share Posted January 1, 2012 Thanks for the help. I am trying to follow the book as close as possible. and the book has shortcuts like <? I did change this to <?php and plan on using that in my code. I did change the quotes did not see that this time must have copied that to make sure I was typing correct. The page is URL encoding (I believe this is what it is doing) hiUser2.php?"userName"=Shannon but the page is not changing. I have tried this on my website I have running and on my localhost and get the same results. Thanks again Quote Link to comment https://forums.phpfreaks.com/topic/254167-newbie-help-please/#findComment-1303097 Share on other sites More sharing options...
Pikachu2000 Posted January 1, 2012 Share Posted January 1, 2012 Is that all of the code for that script, and is it the actual code you're using? Quote Link to comment https://forums.phpfreaks.com/topic/254167-newbie-help-please/#findComment-1303100 Share on other sites More sharing options...
QuickOldCar Posted January 1, 2012 Share Posted January 1, 2012 There is no $_POST form for that script, unless you want to retrieve from a $_GET some changes <html> <head> <title>Hi User</title> </head> <body> <?php $userName = $_POST['userName']; if (empty($userName)){ print <<<HERE <h1>Hi User</h1> <form action="" method="post"> please enter you name: <input type = "text" name = "userName"> <br> <input type = "submit"> </form> HERE; }else{ print "<h1>Hi There, $userName !</h1>"; }//end ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/254167-newbie-help-please/#findComment-1303102 Share on other sites More sharing options...
Pikachu2000 Posted January 1, 2012 Share Posted January 1, 2012 It also appears that the code is written to rely on register_globals = On (which is a bad thing), and that would indicate that the book you're using is probably quite old. You should consider a newer book. Quote Link to comment https://forums.phpfreaks.com/topic/254167-newbie-help-please/#findComment-1303103 Share on other sites More sharing options...
extremeshannon Posted January 2, 2012 Author Share Posted January 2, 2012 Thanks everyone for the feed back. I have decided not to continue with this book. I have found mistakes and things just not working. I have been wondering how the info was suppose to be passed between all the scripts. Any suggestions on a book for PHP/MSQL Thanks Quote Link to comment https://forums.phpfreaks.com/topic/254167-newbie-help-please/#findComment-1303204 Share on other sites More sharing options...
wolfcry Posted January 2, 2012 Share Posted January 2, 2012 One of my favorites is PHP for Absolute Beginners. I know you said you weren't doing the code anymore, but I have to add something: <input type = “text” name = “userName”> I'm going to guess, that since you're not using $_GET or $_POST (which you should be to pass the data), another issue could be the use of those special quotes are messing things up a bit too. Just use regular double quotes. I could be wrong about that though. Quote Link to comment https://forums.phpfreaks.com/topic/254167-newbie-help-please/#findComment-1303209 Share on other sites More sharing options...
QuickOldCar Posted January 2, 2012 Share Posted January 2, 2012 To be honest many of the books , even though they have newer versions, still have old or incorrect practices in them. Most of the time you are just copying chunks of code and they briefly inform you on some of the why, and alternate methods. In general it will be what that author felt it should be. There are a few places to get you started online. http://www.tizag.com/phpT/index.php http://www.w3schools.com/php/ http://devzone.zend.com/6/php-101-php-for-the-absolute-beginner/ http://www.web3mantra.com/2011/06/21/35-best-php-video-tutorials/ And the best place yet, the php manual, usually with some examples and explanations. http://php.net/manual/en/tutorial.php And if ever get stuck with a code, can always drop into phpfreaks for assistance. Quote Link to comment https://forums.phpfreaks.com/topic/254167-newbie-help-please/#findComment-1303218 Share on other sites More sharing options...
extremeshannon Posted January 3, 2012 Author Share Posted January 3, 2012 Thanks everyone turn on register_globals did the trick. This is on a Ubuntu desktop running LAMP. I am hoping the book moves forward with some better practices and stat using _get and _post. Quote Link to comment https://forums.phpfreaks.com/topic/254167-newbie-help-please/#findComment-1303796 Share on other sites More sharing options...
scootstah Posted January 3, 2012 Share Posted January 3, 2012 Thanks everyone turn on register_globals did the trick. No no no. You want to turn register globals OFF. It is a huge security concern. Quote Link to comment https://forums.phpfreaks.com/topic/254167-newbie-help-please/#findComment-1303799 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.