Learning PHP and MySQL

Thursday, July 06, 2006

Welcome to the O’Reilly Learning PHP & MySQL blog

Here you will find code directly from the book, error listings, code fixes, and trivia about the computing world. Welcome. The authors of Learning PHP & MySQL Michele Davis and Jon Phillips will also be happy to answer any questions. So please use your real name when signing in! We look forward to a lively blog with lots of comments!

Source code for each chapter is posted under the catagories on the right side bar.

Posted by admin on 07/06 at 11:58 AM
Blogging • (4) Comments • (513) TrackbacksPermalink

Brett Merkey Book Review

This review was taken from amazon.com

The Very Book for the Very Beginner, June 29, 2006

Reviewer: Brett Merkey (Palm Harbor, FL United States)

This book will take you from a basic understanding of creating static HTML to an elementary but quite nifty practical knowledge of serving up dynamic Web pages on your own.

Chapters 1-6 take you through basic orientation, the installation of Apache, PHP and MySQL, followed by an intro to PHP statements.

Chapters 7-9 introduce database concepts and step you through getting PHP to talk to MySQL.

Chapters 10-17 begin the process of creating forms and other components of Web sites and applications following all the way through to integrating some sample applications.

Each step and procedure has ample code printouts, logic diagrams and output screenshots. Review of knowledge was done well. One feature of this book you should take advantage of is the question section at the end of each chapter. I usually find these irritating and skip them because often the questions don’t reinforce learning and no answers are provided. The questions in this book *are* well constructed and the answers *are* provided.

Quibbles: Be prepared for a bit of keyboarding. O’Reilly provides a site for the book but the example code is not available for download. Your first bout of keying code may end in failure because the authors forget that in the first examples (the most important ones for an absolute beginner!) they need to recall being a beginner. They ask you to write out and save “a simple HTML document.” I did that. The example did not work on the server. I checked this, I checked that, I re-typed the code, I typed other examples. No luck. Then I stumbled onto changing the extension of my .html file to .php and all was well. See my point?

Posted by krautgrrl on 07/06 at 10:22 AM
Blogging • (5) Comments • (391) TrackbacksPermalink

Friday, August 18, 2006

Creating myapp/index.php

<?php require_once("smarty.php");
$smarty->assign('test',  '123');
$smarty->display('index.tpl');
?>

Posted by krautgrrl on 08/18 at 11:53 AM
Chapter 10 Code • (110) Comments • (894) TrackbacksPermalink

Monday, September 25, 2006

Cross-Site Scripting Attacks

To guard against these attacks, you should pass any strings that came from a user through the htmlentities function. It takes the format:

htmlentities(string_to_clean)

For example:

print  "The title of the book is: " 
htmlentities($_POST['title']);

Here’s an example of what htmlentities does to the string:

<?php
$sample  
=  "A  sample  is  <i>italics</i>";
echo  
htmlentities($sample);
?>

When executed, this returns:

A sample is <i>italics</i>

Here’s a script to display the title table with the htmlentities functionality added:

<?php require_once('db_login.php'); require_once('DB.php');
$connection  =  DB::connect("mysql://$db_username:$db_password@$db_host/$db_database");
if  (
DB::isError($connection)){
die  ("Could  not  connect  to  the  database:  <br  />".  DB::errorMessage($connection));
}
//  Dislplay  the  table
$query  =  "SELECT  *  FROM  `books`";
$result  =  $connection->query($query);
if  (
DB::isError($result)){
die("Could  not  query  the  database:  <br  />".$query."  ".DB::errorMessage($result));
}
echo  '<table  border="1">';
echo  
"<tr><th>Title</th><th>Pages</th></tr>";
while  (
$result_row  =  $result->fetchRow(DB_FETCHMODE_ASSOC))  {
echo  "<tr><td>";
echo  
htmlentities($result_row["title"])  .  '</td><td>';
echo  
htmlentities($result_row["pages"])  .  '</td></tr>';
}
echo  "</table>";
$connection->disconnect();
?>

Posted by krautgrrl on 09/25 at 11:11 AM
Chapter 12 Code • (5) Comments • (75) TrackbacksPermalink

Wednesday, August 09, 2006

Example 03-01 All you need to start with PHP is a simple HTML document

<html>
<
head>
<
title>Hello  World</title>
</
head>
<
body>
<
p>I  sure  wish  I  had  something  to  say.</p>
</
body>
</
html>

Posted by admin on 08/09 at 03:22 PM
Chapter 3 Code • (3) Comments • (1758) TrackbacksPermalink

Thursday, July 06, 2006

Example 03-02 Adding PHP Code to an HTML File

<html>
    <
head>
        <
title>Hello World</title>
    </
head>
    <
body>
        echo(
"<p>Now I have something to say.</p>");
    </
body>
</
html>

This should be saved out with the .php extension, not the .html extension.

Posted by krautgrrl on 07/06 at 01:41 PM
Chapter 3 Code • (137) Comments • (1862) TrackbacksPermalink

Example 03-03 Calling echo() and print()

<html>
    <
head>
        <
title>Hello World</title>
    </
head>
    <
body>
        <?
php

        
echo ("Hello world!<br />");
        print (
'Goodbye.<br />');
        print 
'Over and out.';

        
?> 
    </body>
</html>

Posted by krautgrrl on 07/06 at 02:38 PM
Chapter 3 Code • (4) Comments • (2310) TrackbacksPermalink

Wednesday, August 09, 2006

Example 03-04 The HTML markup produced by the PHP code

<html>
<
head>
<
title>Hello  World</title>
</
head>
<
body>
Hello  world!<br  />Goodbye.<br  />Over  and  out.
</
body>
</
html>

Posted by admin on 08/09 at 03:23 PM
Chapter 3 Code • (26) Comments • (4349) TrackbacksPermalink

Wednesday, July 19, 2006

Example 03-05 Using comments to make your code easier to read

<html>
<
head>
<
title>Hello  World</title>
</
head>
<
body>
<?
php

//  A  single  line  comment  could  say  that  we  are  going  to
//  print  hello  world.

/*  This  is  how  to  do  a
multi-line  comment  and  could  be  used to  comment  out  a  block of  code  */

echo("Hello  world!<br  />");
print(
'Goodbye.<br  />');

?>
</body>
</html>

Posted by krautgrrl on 07/19 at 03:37 PM
Chapter 3 Code • (1) Comments • (368) TrackbacksPermalink

Wednesday, August 09, 2006

Example 03-06 Reassigning a variable

<?php
$age  
=  30;
$age  =  31;
echo  
$age;
?>

Posted by admin on 08/09 at 03:25 PM
Chapter 3 Code • (2) Comments • (204) TrackbacksPermalink

Wednesday, July 19, 2006

Example 03-07 The default handling of variable scope

<?php

//  define  a  function function  birthday(){
//  Set  age  to  1
$age  =  1;
}

//  Set  age  to  30
$age  =  30;

//  Call  the  function
birthday();

//  Display  the  age echo  $age;

?>

Displays:

30

Posted by krautgrrl on 07/19 at 03:38 PM
Chapter 3 Code • (5) Comments • (788) TrackbacksPermalink

Example 03-08 Using a global variable changes the result

<?php

//  Define  a  function function  birthday(){
//  Define  age  as  a  global  variable
global  $age;

//  Add  one  to  the  age  value


//  set  age  to  30
$age  =  30;

//  Call  the  function birthday();

//  Display  the  age echo  $age;

?>

Displays:

31

Posted by krautgrrl on 07/19 at 03:40 PM
Chapter 3 Code • (3) Comments • (97) TrackbacksPermalink

Example 03-09 A static variable remembering its last value

<?php
//  Define  the  function function  birthday(){
//  Define  age  as  a  static  variable static  $age  =  0;

//  Add  one  to  the  age  value
$age  =  $age  +  1;

//  Print  the  static  age  variable
echo  "Birthday  number  $age<br  />";
}

//  Set  age  to  30
$age  =  30;

//  Call  the  function  twice birthday();
birthday();

//  Display  the  age
echo  "Age:  $age<br  />";

?>

Displays:

Birthday number 1
Birthday number 2
Age:  30

Posted by krautgrrl on 07/19 at 03:41 PM
Chapter 3 Code • (4) Comments • (654) TrackbacksPermalink

Example 03-10 PHP_SELF being used with a file called test.php

<?php
echo  $_SERVER["PHP_SELF"];
?>

Outputs:

/test.php

Posted by krautgrrl on 07/19 at 03:42 PM
Chapter 3 Code • (4) Comments • (503) TrackbacksPermalink

Example 03-11 Working with strings

<?php
$my_string  
=  "Margaritaville  -  Suntan  Oil  Application!";
echo  
"Margaritaville  -  Suntan  Oil  Application!";
?>

Posted by krautgrrl on 07/19 at 03:43 PM
Chapter 3 Code • (4) Comments • (1002) TrackbacksPermalink
Page 1 of 15 pages  1 2 3 >  Last »

Statistics

This page has been viewed 374207 times
Page rendered in 0.2048 seconds
Total Entries: 224
Total Comments: 16
Total Trackbacks: 307338
Most Recent Entry: 09/27/2006 12:39 pm
Most Recent Comment on: 10/26/2007 10:00 am
Total Members: 2
Total Logged in members: 0
Total guests: 12
Total anonymous users: 0
Most Recent Visitor on: 02/06/2012 06:16 am
The most visitors ever was 1103 on 11/20/2007 12:50 pm

Referrers

Powered by ExpressionEngine