Apress

PHP for Absolute Beginners

By Jason Lengstorf

PHP for Absolute Beginners Cover Image

Get started in web development using PHP. Even if you've never programmed before, author Jason Lengstorf introduces you to PHP by building a PHP-based blogging site while covering all the good coding practices and skills that you'll need when you start your own projects.

Full Description

  • ISBN13: 978-1-4302-2473-0
  • 408 Pages
  • User Level: Beginner
  • Publication Date: October 14, 2009
  • Available eBook Formats: EPUB, MOBI, PDF
  • Print Book Price: $34.99
  • eBook Price: $24.99
Buy eBook Buy Print Book Add to Wishlist

Related Titles

Full Description

Get started in web development using PHP. Even if you've never programmed before, author Jason Lengstorf introduces you to PHP by building a PHP-based blogging site while covering all the good coding practices and skills that you'll need when you start your own projects.

  • Create web content with version 5.3 of PHP
  • Learn good coding practices from the very beginning
  • Learn how systems like WordPress work

Jason Lengstorf takes a practical approach to teaching you how to build a content management system. You'll dive into writing web applications and be guided by the author's supportive explanations, rather than learning elements of the PHP language and viewing examples after.

PHP for Absolute Beginners starts slowly and covers everything you need to know about beginning web development using PHP. Even the most inexperienced web developer will find this book accessible.

What you’ll learn

  • Install Apache, MySQL, and PHP
  • Navigate the PHP language
  • Learn the basics of writing clean code
  • Talk to a database
  • Make a PHP site more secure
  • Create a complete blogging site

Who this book is for

PHP for Absolute Beginners is written for the complete novice; no previous coding knowledge is assumed, and all concepts are explained to ensure maximum understanding.

However, later chapters in the book may appeal to intermediate programmers looking to improve their abilities in the area of developing content management systems or those interested in making the move from procedural code to the more modular object-oriented approach.

Table of Contents

Table of Contents

  1. Setting Up the PHP Development Environment
  2. Understanding PHP: Language Basics
  3. Passing Information with PHP
  4. Working with Databases
  5. Building the Entry Manager
  6. Adding Support for Multiple Pages
  7. Updating and Deleting Entries
  8. Adding the Ability to Upload Images
  9. Syndicating the Blog
  10. Adding a Commenting System to Your Blog
  11. Adding Password Protection to Administrative Links
  12. Finishing Touches
Source Code/Downloads

Downloads are available to accompany this book.

Your operating system can likely extract zipped downloads automatically, but you may require software such as WinZip for PC, or StuffIt on a Mac.

Errata

If you think that you've found an error in this book, please let us know about it. You will find any confirmed erratum below, so you can check if your concern has already been addressed.

* Required Fields

On page 30:

I think i found something on page 30 that hasn't been logged as errata yet. workaround is simple but people who are uh...more of a beginner than even me might get confused on what to do.

Code on page 30 that presents an error on the browser is:


<?php
echo '<p>This is some text</p>';
?>
<p>Some of this text is static, <?php echo 'but this sure isn't!'; ?></p>
<?php echo '<p>'; ?>
This text was enclosed in paragraph tags that were generated by PHP.
<?php echo '</p>';?>


line 4's 'but this sure isn't' is the one in question. you have 3 " ' "'s in there. two is required for encapsulation so the ide is most likely confused at runtime and thinks the one in the middle ends and properly traps the intended elements inside leaving " t " on it's own and the last ' as somewhat of an opening bracket with no closeure. substituting " for ' as the opening and closing brackets of course made it possible for me to use " ' " as intended.


On page 43:
The first note on the page reads:
"Because print() is a language construct..."

It should read:
"Because echo() is a language construct..."

On page 90:

Error message: Fatal error: Can't use function return > value in write context in

For future reference: The code is from 'PHP for Absolute Beginners' by Jason Lengstorf (2009), pages 90-91, Chapter 3, $_SESSION

On page 133:
The inconsistent problem started with subtitle Performing the Initial Verification" on page 133


<?php
if($_SERVER['REQUEST_METHOD']=='POST'
&& $_POST['submit']=='Save Entry'
&& !empty($_POST['title'])
&& !empty($_POST['entry']))
{

On page 133:

There is inconsistent PHP code in this book. So far, the inconsistent PHP code I found on the part 2 "Building Your Blog".

The inconsistent problem started with subtitle Performing the Initial Verification" on page 133


<?php
if($_SERVER['REQUEST_METHOD']=='POST'
&& $_POST['submit']=='Save Entry'
&& !empty($_POST['title'])
&& !empty($_POST['entry']))
{

This PHP snippet code is no the same found on page 135.

<?php
if($_SERVER['REQUEST_METHOD']=='POST'
&& $_POST['submit']=='Save Entry')
{

Here, if you used this PHP snippet of the page 135 inside of your code, you will have problems with the Mysql table. Because, if you don't type any title or entry values in the HTML form, the PHP script will insert into the Mysql table with Null values in title and entry columns. It is a problem.


I found other one inconsistent PHP code on page 136

/ Save the entry into the database
$sql = "INSERT INTO entries (title, entry) VALUES (?, ?)";
$stmt = $db->prepare($sql);
$stmt->execute(array($title, $entry));
$stmt->closeCursor();

The problem with this PHP snippet code is about $title, $entry variables. They are missing. I mean no variable values to insert into the Mysql table.

On page 137, I found the a similiar PHP snippet code, but this one is correct.

// Save the entry into the database
$sql = "INSERT INTO entries (title, entry) VALUES (?, ?)";
$stmt = $db->prepare($sql);
$stmt->execute(array($_POST['title'], $_POST['entry']));
$stmt->closeCursor();

Here, they are title and entry variable values to insert into Mysql table.


As you see, this book has problems with the PHP code. If you are a PHP beginner guy, maybe you will be confused when you are using this PHP code.



On page 135:
This PHP snippet code is no the same found on page 135.

<?php
if($_SERVER['REQUEST_METHOD']=='POST'
&& $_POST['submit']=='Save Entry')
{

Here, if you used this PHP snippet of the page 135 inside of your code, you will have problems with the Mysql table. Because, if you don't type any title or entry values in the HTML form, the PHP script will insert into the Mysql table with Null values in title and entry columns. It is a problem.

On page 136:
I found another inconsistent PHP code on page 136

/ Save the entry into the database
$sql = "INSERT INTO entries (title, entry) VALUES (?, ?)";
$stmt = $db->prepare($sql);
$stmt->execute(array($title, $entry));
$stmt->closeCursor();

The problem with this PHP snippet code is about $title, $entry variables. They are missing. I mean no variable values to insert into the Mysql table.

On page 137:
On page 137, I found the a similiar PHP snippet code, but this one is correct.

// Save the entry into the database
$sql = "INSERT INTO entries (title, entry) VALUES (?, ?)";
$stmt = $db->prepare($sql);
$stmt->execute(array($_POST['title'], $_POST['entry']));
$stmt->closeCursor();

Here, they are title and entry variable values to insert into Mysql table.

On page 167:
$stmt->execute(array($_GET['id']));

must be

$stmt->execute(array($id));

On page 257:
When debugging the code, there isn't defined any $d[2] and $d[3].. Aka the resampling fails, and it returns the error "Could not resample the image!" - I even tested out the source I can download, it has the same problem.

I can't finish this book, I did like it tho, but please is there a way to solve this?

On page 330:

When navigating to http://localhost/simple_blog/admin, I get the following error message:

Notice: Undefined index: url in C:\xampp\htdocs\simple_blog\index.php on line 69

Notice: Undefined index: image in C:\xampp\htdocs\simple_blog\index.php on line 81

I have even tried the source code and I have the same problem. Does anyone have a suggestion as to how this can be addressed?