Jump to content

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
https://forums.phpfreaks.com/topic/314068-learning-php-7-from-book-learning-php-7/
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!

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!

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.

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

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.

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.

 

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.

image.png.a075f247c77ba28ac09f9140d53cacda.png

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

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.

×
×
  • 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.