Skip to content

Commit

Permalink
First commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Apress committed Oct 19, 2016
0 parents commit 5b3e7cb
Show file tree
Hide file tree
Showing 117 changed files with 10,419 additions and 0 deletions.
Binary file added 9781484217290.jpg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
5 changes: 5 additions & 0 deletions Example Code Files/chapter1/p1helloworld.php
@@ -0,0 +1,5 @@
<?php

print "Hello World!";

?>
46 changes: 46 additions & 0 deletions Example Code Files/chapter2/e21Ajax_Example_JavaScript.js
@@ -0,0 +1,46 @@
function getXMLHttp()
{
var xmlHttp;
try
{
xmlHttp = new XMLHttpRequest();
}
catch(e)
{
//Internet Explorer is different than the others
try
{
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e)
{
alert("Old browser? Upgrade today so you can use AJAX!")
return false;
}
}
}
return xmlHttp;
}
function AjaxRequest()
{
var xmlHttp = getXMLHttp();
xmlHttp.onreadystatechange = function()
{
if(xmlHttp.readyState == 4)
{
HandleResponse(xmlHttp.responseText);
}
}
xmlHttp.open("GET", "myfirstprogram.php", true);
xmlHttp.send(null);
}
function HandleResponse(response)
{
document.getElementById('AjaxResponse').innerHTML = response;
}
22 changes: 22 additions & 0 deletions Example Code Files/chapter2/e22helloworldajax.html
@@ -0,0 +1,22 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head> <title>PHP Ajax Demo</title>
<meta charset="utf-8">
<link href="e23ajaxdemo.css" rel="stylesheet">
<script type='text/javascript' src='e21Ajax_Example_JavaScript.js'></script>
</head>
<body>
<div id="wrapper">
<div id="header"> <h1>PHP Ajax Demo</h1> </div>
<div id="content"> <h2>"Watch it!!"</h2>
<p>The words below will be replaced by "Hello World" which is pulled from the 'myfirstprogram.php' file via AJAX.</p>
<h2>AJAX DEMO</h2>
<input type='button' onclick='AjaxRequest();' value='Find Hello World!'/><br /><br />
<div id='AjaxResponse'>
Pay attention... Notice when you click the button that only this section changes.
</div> </div> <!-- end of content -->
<div id="footer">Copyright &copy; 2014 Steve Prettyman
</div><!-- end of footer -->
</div> <!-- end of wrapper -->
</body>
</html>
27 changes: 27 additions & 0 deletions Example Code Files/chapter2/e23ajaxdemo.css
@@ -0,0 +1,27 @@
body { background-color: #000000;
font-family: Arial, Verdana, sans-serif; }
#wrapper { margin: 0 auto;
width: 85%;
min-width: 800px;
background-color: #cc0000;
color: #000066; }
#header { background-color: #ff0000;
color: #00005D;
font-size: 125%;
padding: 20px 20px 20px 160px;
background-repeat: no-repeat; }
h1 { margin-bottom: 10px; }
#content { background-color: #ffffff;
color: #000000;
padding: 10px 20px;
overflow: auto; }
#footer { font-size: 80%;
text-align: center;
padding: 5px;
background-color: #0000FF;
color: #ffffff;
clear: both;}
h2 { color: #000000;
font-family: Arial, sans-serif; }
#floatright { float: right;
margin: 10px; }
22 changes: 22 additions & 0 deletions Example Code Files/chapter2/e23mobilehelloworldajax.html
@@ -0,0 +1,22 @@
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<head> <title>PHP Ajax Demo</title>
<meta charset="utf-8">
<link href="e23ajaxdemo.css" rel="stylesheet">
<link href="e24ajaxdemomobile.css" rel="stylesheet" media="only screen and (max-device-width:480px)">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script type='text/javascript' src='e21Ajax_Example_JavaScript.js'></script>
</head>
<body>
<div id="wrapper">
<div id="header"> <h1>PHP Ajax Demo</h1> </div>
<div id="content"> <h2>"Watch it!!"</h2>
<p>The words below will be replaced by "Hello World" which is pulled from the 'myfirstprogram.php' file via AJAX.</p>
<h2>AJAX DEMO</h2>
<input type='button' onclick='AjaxRequest();' value='Find Hello World!'/><br /><br />
<div id='AjaxResponse'>
Pay attention... Notice when you click the button that only this section changes.
</div> </div> <!-- end of content -->
<div id="footer">Copyright &copy; 2014 Steve Prettyman
</div><!-- end of footer -->
</div> <!-- end of wrapper -->
</body>
29 changes: 29 additions & 0 deletions Example Code Files/chapter2/e24ajaxdemomobile.css
@@ -0,0 +1,29 @@
body { background-color: #000000;
font-family: Arial, Verdana, sans-serif;
margin: 0; }
#wrapper { margin: 0 auto;
width: 100%;
margin: 0;
min-width: 0px;
background-color: #cc0000;
color: #000066; }
#header { background-color: #ff0000;
color: #00005D;
font-size: 100%;
padding: 0.5px 0.5px 0.5px 0.5px; }
h1 { margin: 0px; }
#content { background-color: #ffffff;
color: #000000;
padding: 0.5px 0.5px;
overflow: auto; }
#footer { font-size: 80%;
text-align: left;
padding: 0px;
background-color: #0000FF;
color: #ffffff;
clear: both;}
h2 { color: #000000;
font-family: Arial, sans-serif;
margin: 0px; }
#floatright { float: none;
margin: 0px; }
8 changes: 8 additions & 0 deletions Example Code Files/chapter2/e25dynamichtml.php
@@ -0,0 +1,8 @@
<?php
print '<html>';
print '<head><title>My Program</title></head>';
print '<body>';
print '<h1>Hello World</h1>';
print '</body>';
print '</html>';
?>
14 changes: 14 additions & 0 deletions Example Code Files/chapter2/e26callmyself.php
@@ -0,0 +1,14 @@
<?php
if (isset($_POST['submitbutton']))
{
print "<h1> Hello World </h1>";
}
else
{
print "<html><head><title>PHP Example</title></head>";
print "<form method='post' action='e26callmyself.php'>";
print "<input type='submit' id='submitbutton' name='submitbutton' value='Find Hello World!'/>";
print "</form>";
print "</body></html>";
}
?>
57 changes: 57 additions & 0 deletions Example Code Files/chapter3/e310dog.php
@@ -0,0 +1,57 @@
<?php
class Dog
{
// ----------------------------------------- Properties -----------------------------------------
private $dog_weight = 0;
private $dog_breed = "no breed";
private $dog_color = "no color";
private $dog_name = "no name";

// ---------------------------------- Set Methods ----------------------------------------------
function set_dog_name($value)
{
$error_message = TRUE;
(ctype_alpha($value) && strlen($value) <= 20) ? $this->dog_name = $value : $error_message = FALSE;
return $error_message;
}
function set_dog_weight($value)
{
$error_message = TRUE;
(ctype_digit($value) && ($value > 0 && $value <= 120)) ? $this->dog_weight = $value : $error_message = FALSE;
return $error_message;
}
function set_dog_breed($value)
{
$error_message = TRUE;
(ctype_alpha($value) && strlen($value) <= 35) ? $this->dog_breed = $value : $error_message = FALSE;
return $error_message;
}
function set_dog_color($value)
{
$error_message = TRUE;
(ctype_alpha($value) && strlen($value) <= 15) ? $this->dog_color = $value : $error_message = FALSE;
return $error_message;
}
// ----------------------------------------- Get Methods ------------------------------------------------------------
function get_dog_name()
{
return $this->dog_name;
}
function get_dog_weight()
{
return $this->dog_weight;
}
function get_dog_breed()
{
return $this->dog_breed;
}
function get_dog_color()
{
return $this->dog_color;
}
function get_properties()
{
return "$this->dog_weight,$this->dog_breed,$this->dog_color.";
}
}
?>
24 changes: 24 additions & 0 deletions Example Code Files/chapter3/e311lab.php
@@ -0,0 +1,24 @@
<?php
Require_once("e310dog.php");
$lab = new Dog;
// ------------------------------Set Properties--------------------------
$dog_error_message = $lab->set_dog_name('Fred');
print $dog_error_message == TRUE ? 'Name update successful<br/>' : 'Name update not successful<br/>';

$dog_error_message = $lab->set_dog_weight(50);
print $dog_error_message == TRUE ? 'Weight update successful<br />' : 'Weight update not successful<br />';

$dog_error_message = $lab->set_dog_breed('Lab');
print $dog_error_message == TRUE ? 'Breed update successful<br />' : 'Breed update not successful<br />';

$dog_error_message = $lab->set_dog_color('Yellow');
print $dog_error_message == TRUE ? 'Color update successful<br />' : 'Color update not successful<br />';
// ------------------------------Get Properties--------------------------
print $lab->get_dog_name() . "<br/>";
print $lab->get_dog_weight() . "<br />";
print $lab->get_dog_breed() . "<br />";
print $lab->get_dog_color() . "<br />";
$dog_properties = $lab->get_properties();
list($dog_weight, $dog_breed, $dog_color) = explode(',', $dog_properties);
print "Dog weight is $dog_weight. Dog breed is $dog_breed. Dog color is $dog_color.";
?>
77 changes: 77 additions & 0 deletions Example Code Files/chapter3/e312dog.php
@@ -0,0 +1,77 @@
<?php
class Dog
{
// ----------------------------------------- Properties -----------------------------------------
private $dog_weight = 0;
private $dog_breed = "no breed";
private $dog_color = "no color";
private $dog_name = "no name";
private $error_message = "??";
// ---------------------------------- Constructor ----------------------------------------------
function __construct($value1, $value2, $value3, $value4)
{

$name_error = $this->set_dog_name($value1) == TRUE ? 'TRUE,' : 'FALSE,';
$breed_error = $this->set_dog_breed($value2) == TRUE ? 'TRUE,' : 'FALSE,';
$color_error = $this->set_dog_color($value3) == TRUE ? 'TRUE,' : 'FALSE,';
$weight_error= $this->set_dog_weight($value4) == TRUE ? 'TRUE' : 'FALSE';

$this->error_message = $name_error . $breed_error . $color_error . $weight_error;

}
//------------------------------------toString--------------------------------------------------
public function __toString()
{
return $this->error_message;
}

// ---------------------------------- Set Methods ----------------------------------------------
function set_dog_name($value)
{
$error_message = TRUE;
(ctype_alpha($value) && strlen($value) <= 20) ? $this->dog_name = $value : $this->error_message = FALSE;
return $this->error_message;
}
function set_dog_weight($value)
{
$error_message = TRUE;
(ctype_digit($value) && ($value > 0 && $value <= 120)) ? $this->dog_weight = $value : $this->error_message = FALSE;
return $this->error_message;
}
function set_dog_breed($value)
{
$error_message = TRUE;
(ctype_alpha($value) && strlen($value) <= 35) ? $this->dog_breed = $value : $error_message = FALSE;
return $this->error_message;
}
function set_dog_color($value)
{
$error_message = TRUE;
(ctype_alpha($value) && strlen($value) <= 15) ? $this->dog_color = $value : $this->error_message = FALSE;
return $this->error_message;
}
// ----------------------------------------- Get Methods ------------------------------------------------------------
function get_dog_name()
{
return $this->dog_name;
}
function get_dog_weight()
{
return $this->dog_weight;
}
function get_dog_breed()
{
return $this->dog_breed;
}
function get_dog_color()
{
return $this->dog_color;
}
function get_properties()
{
return "$this->dog_weight,$this->dog_breed,$this->dog_color.";
}


}
?>
32 changes: 32 additions & 0 deletions Example Code Files/chapter3/e313lab.php
@@ -0,0 +1,32 @@
<?php
Require_once("e312dog.php");
$lab = new Dog('Fred','Lab','Yellow','100');

list($name_error, $breed_error, $color_error, $weight_error) = explode(',', $lab);

print $name_error == 'TRUE' ? 'Name update successful<br/>' : 'Name update not successful<br/>';
print $breed_error == 'TRUE' ? 'Breed update successful<br/>' : 'Breed update not successful<br/>';
print $color_error == 'TRUE' ? 'Color update successful<br/>' : 'Color update not successful<br/>';
print $weight_error == 'TRUE' ? 'Weight update successful<br/>' : 'Weight update not successful<br/>';

// ------------------------------Set Properties--------------------------
$dog_error_message = $lab->set_dog_name('Sally');
print $dog_error_message == TRUE ? 'Name update successful<br/>' : 'Name update not successful<br/>';

$dog_error_message = $lab->set_dog_weight('5');
print $dog_error_message == TRUE ? 'Weight update successful<br />' : 'Weight update not successful<br />';

$dog_error_message = $lab->set_dog_breed('Labrador');
print $dog_error_message == TRUE ? 'Breed update successful<br />' : 'Breed update not successful<br />';

$dog_error_message = $lab->set_dog_color('Brown');
print $dog_error_message == TRUE ? 'Color update successful<br />' : 'Color update not successful<br />';
// ------------------------------Get Properties--------------------------
print $lab->get_dog_name() . "<br/>";
print $lab->get_dog_weight() . "<br />";
print $lab->get_dog_breed() . "<br />";
print $lab->get_dog_color() . "<br />";
$dog_properties = $lab->get_properties();
list($dog_weight, $dog_breed, $dog_color) = explode(',', $dog_properties);
print "Dog weight is $dog_weight. Dog breed is $dog_breed. Dog color is $dog_color.";
?>

0 comments on commit 5b3e7cb

Please sign in to comment.