Markus1954 Posted October 21, 2021 Share Posted October 21, 2021 Hi, I have a book called Learning PHP 7. Yesterday I installed Mysql, PHP 8 and Apache 2.4. Apache and php both work. I copied some code from the book into Notepad++. It does not work. Here is the code: <?php $looking = isset($_GET)['title']) || isset($_GET['author']); ?> <!doctype html> <html lang = "en"> <head> <meta charset ="UTF-8"> <title>Bookstore</title> </head> <body> <p><you looking'? <?php echo (int) $looking; ?> </p> <p>The book you are looking for is </p> <ul> <li><b>Title</b>: <?php echo $_get['title']; ?></li> <li><b>Author</b> <?php echo $_get[author']; ?></li> </ul> </body> </html> I got rid of the misspelled words. I made a directory called book and put this file in there. I did a localhost/book. It did not work so I moved the file to htdocs, it still did not work. Right now I am baffled. Anyone have an idea what is wrong? Your help is appreciated. Mark Quote Link to comment https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/ Share on other sites More sharing options...
jarvis Posted October 21, 2021 Share Posted October 21, 2021 You have errors in your code: <?php $looking = isset($_GET['title']) || isset($_GET['author']); ?> <!doctype html> <html lang = "en"> <head> <meta charset ="UTF-8"> <title>Bookstore</title> </head> <body> <p>you looking <?php echo (int) $looking; ?> </p> <p>The book you are looking for is </p> <ul> <li><b>Title</b>: <?php echo $_get['title']; ?></li> <li><b>Author</b> <?php echo $_get['author']; ?></li> </ul> </body> </html> Is your debugging/error checking on? Once I fixed the errors in line 2 and 15, it displays but still flags the following: Notice: Undefined variable: _get in index.php on line 14 Notice: Undefined variable: _get in index.php on line 15 Your code also seemed a tad scruffy given it was a copy/paste from a book! Quote Link to comment https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/#findComment-1591285 Share on other sites More sharing options...
jarvis Posted October 21, 2021 Share Posted October 21, 2021 Am no expert but perhaps something more like: <?php $looking = isset($_GET['title']) || isset($_GET['author']); $title = isset($_GET['title']) ? $_GET['title'] : 'No title set'; $author = isset($_GET['author']) ? $_GET['author'] : 'No author set'; ?> <!doctype html> <html> <head> <meta charset="utf-8"> <title>Bookstore</title> </head> <body> <p>The book you're looking for is:</p> <ul> <li><strong>Title</strong>: <?php echo $title; ?></li> <li><strong>Author</strong>: <?php echo $author; ?></li> </ul> </body> </html> Others with way more experience may be able to improve further but that should at the very least get you up and running! Quote Link to comment https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/#findComment-1591286 Share on other sites More sharing options...
ginerjm Posted October 21, 2021 Share Posted October 21, 2021 If that first line of code was in your new book, I'd stop using that book. That code doesn't work in my php 7. Perhaps it is new for php 8, but I doubt it. It uses an OR construct (||) that is part of an if statement usually, not an ordinary assignment statement. Quote Link to comment https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/#findComment-1591287 Share on other sites More sharing options...
Barand Posted October 21, 2021 Share Posted October 21, 2021 Save jarvis's latest code in "/htdocs/book.php" then try this in your browser's address bar http://localhost/book.php?title=War+and+Peace&author=Tolstoy and see if that works. Quote Link to comment https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/#findComment-1591289 Share on other sites More sharing options...
ginerjm Posted October 21, 2021 Share Posted October 21, 2021 (edited) And now I see the bad paren..... And - have learned a new way of evaluating conditions. Edited October 21, 2021 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/#findComment-1591291 Share on other sites More sharing options...
Markus1954 Posted October 22, 2021 Author Share Posted October 22, 2021 Hi All, Thanks for responding, I made some corrections and it still doesn't work. The book is from a British publisher. I have not had much luck with these books. I unfortunately purchase two of these crappy books on C++ and their support staff is horrible. I am using the php.ini production version. I removed the ; from the is this phi ini production in php.ini. I cannot fin ini_set in this file. Mark Quote Link to comment https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/#findComment-1591314 Share on other sites More sharing options...
Markus1954 Posted October 22, 2021 Author Share Posted October 22, 2021 While all of you are here I have another question. I am using php 8. There is a book called the joy of php published in 2015. Can I use this book with PHP 8? Quote Link to comment https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/#findComment-1591315 Share on other sites More sharing options...
ginerjm Posted October 22, 2021 Share Posted October 22, 2021 17 minutes ago, Markus1954 said: I removed the ; from the is this phi ini production in php.ini. I cannot fin ini_set in this file. I have no idea what you are saying in the above statement. Apparently you are doing something in the php.ini file. Are you sure you know what you are doing? As for running php 8 and using a 6 year old book - Sure it will teach you most of php but the newer features won't be covered nor will it tell you what is no longer supported. Quote Link to comment https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/#findComment-1591316 Share on other sites More sharing options...
Barand Posted October 22, 2021 Share Posted October 22, 2021 1 hour ago, Markus1954 said: There is a book called the joy of php published in 2015. Can I use this book with PHP 8? Use the reference manual at php.net. It's always up-to-date and I believe there is a US version available. Quote Link to comment https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/#findComment-1591318 Share on other sites More sharing options...
Markus1954 Posted October 23, 2021 Author Share Posted October 23, 2021 Hey GingerM, Where am I going to fine error_reporting(E_ALL) and ini_set('display_errors','1'); Quote Link to comment https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/#findComment-1591357 Share on other sites More sharing options...
ginerjm Posted October 23, 2021 Share Posted October 23, 2021 (edited) What do you mean? Those are commands that you put into your script to turn on error checking. You don't have to look for them. And it is 'ginerjm' please. Edited October 23, 2021 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/#findComment-1591358 Share on other sites More sharing options...
Barand Posted October 23, 2021 Share Posted October 23, 2021 The best place to set them is in your php.ini file. If you have startup errors (such as syntax errors) you need display_startup_errors ON, but you can't set that from within a script. This is the relevant section of my development php.ini file. Quote Link to comment https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/#findComment-1591359 Share on other sites More sharing options...
Markus1954 Posted October 24, 2021 Author Share Posted October 24, 2021 Look I have muscle spasms all over my body so I make lots of typos. I also don't have my full ability to concentrate. So I may not be all that clear. As for the book that was written in 2015 as long as the code works, I can try to update it to php 8. Barand, got it. Thanks everyone Quote Link to comment https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/#findComment-1591380 Share on other sites More sharing options...
Barand Posted October 25, 2021 Share Posted October 25, 2021 The main difference I found when switching from v7.4 to v8.0 was that v8.0 is stricter on variable types. You may have to make some minor changes. Quote Link to comment https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/#findComment-1591388 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.