Jump to content

Learning PHP 7 from book Learning PHP 7


Markus1954
 Share

Recommended Posts

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

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.