diff --git a/10/index.txt b/10/index.txt
new file mode 100644
index 0000000..24a4ecf
--- /dev/null
+++ b/10/index.txt
@@ -0,0 +1 @@
+Please note that there are no examples in this folder
diff --git a/11/01.php b/11/01.php
new file mode 100644
index 0000000..9a16353
--- /dev/null
+++ b/11/01.php
@@ -0,0 +1,14 @@
+ PDO::ERRMODE_EXCEPTION,
+ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
+ PDO::ATTR_EMULATE_PREPARES => false,
+ ];
+?>
diff --git a/11/02.php b/11/02.php
new file mode 100644
index 0000000..4c48601
--- /dev/null
+++ b/11/02.php
@@ -0,0 +1,12 @@
+getMessage(), (int)$e->getCode());
+ }
+?>
diff --git a/11/03.php b/11/03.php
new file mode 100644
index 0000000..2c0019a
--- /dev/null
+++ b/11/03.php
@@ -0,0 +1,4 @@
+query($query);
+?>
diff --git a/11/04.php b/11/04.php
new file mode 100644
index 0000000..18fd833
--- /dev/null
+++ b/11/04.php
@@ -0,0 +1,24 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ $query = "SELECT * FROM classics";
+ $result = $pdo->query($query);
+
+ while ($row = $result->fetch())
+ {
+ echo 'Author: ' . htmlspecialchars($row['author']) . "
";
+ echo 'Title: ' . htmlspecialchars($row['title']) . "
";
+ echo 'Category: ' . htmlspecialchars($row['categoryr']) . "
";
+ echo 'Year: ' . htmlspecialchars($row['year']) . "
";
+ echo 'ISBN: ' . htmlspecialchars($row['isbn']) . "
";
+ }
+?>
diff --git a/11/05.php b/11/05.php
new file mode 100644
index 0000000..20aa34a
--- /dev/null
+++ b/11/05.php
@@ -0,0 +1,24 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ $query = "SELECT * FROM classics";
+ $result = $pdo->query($query);
+
+ while ($row = $result->fetch(PDO::FETCH_BOTH)) // Style of fetch
+ {
+ echo 'Author: ' . htmlspecialchars($row['author']) . "
";
+ echo 'Title: ' . htmlspecialchars($row['title']) . "
";
+ echo 'Category: ' . htmlspecialchars($row['categoryr']) . "
";
+ echo 'Year: ' . htmlspecialchars($row['year']) . "
";
+ echo 'ISBN: ' . htmlspecialchars($row['isbn']) . "
";
+ }
+?>
\ No newline at end of file
diff --git a/11/06.php b/11/06.php
new file mode 100644
index 0000000..4676b6b
--- /dev/null
+++ b/11/06.php
@@ -0,0 +1,78 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ if (isset($_POST['delete']) && isset($_POST['isbn']))
+ {
+ $isbn = get_post($pdo, 'isbn');
+ $query = "DELETE FROM classics WHERE isbn=$isbn";
+ $result = $pdo->query($query);
+ }
+
+ if (isset($_POST['author']) &&
+ isset($_POST['title']) &&
+ isset($_POST['category']) &&
+ isset($_POST['year']) &&
+ isset($_POST['isbn']))
+ {
+ $author = get_post($pdo, 'author');
+ $title = get_post($pdo, 'title');
+ $category = get_post($pdo, 'category');
+ $year = get_post($pdo, 'year');
+ $isbn = get_post($pdo, 'isbn');
+
+ $query = "INSERT INTO classics VALUES" .
+ "($author, $title, $category, $year, $isbn)";
+ $result = $pdo->query($query);
+ }
+
+ echo <<<_END
+
+_END;
+
+ $query = "SELECT * FROM classics";
+ $result = $pdo->query($query);
+
+ while ($row = $result->fetch())
+ {
+ $r0 = htmlspecialchars($row['author']);
+ $r1 = htmlspecialchars($row['title']);
+ $r2 = htmlspecialchars($row['category']);
+ $r3 = htmlspecialchars($row['year']);
+ $r4 = htmlspecialchars($row['isbn']);
+
+ echo <<<_END
+
+ Author $r0
+ Title $r1
+ Category $r2
+ Year $r3
+ ISBN $r4
+
+
+_END;
+ }
+
+ function get_post($pdo, $var)
+ {
+ return $pdo->quote($_POST[$var]);
+ }
+?>
\ No newline at end of file
diff --git a/11/07.php b/11/07.php
new file mode 100644
index 0000000..72cfa12
--- /dev/null
+++ b/11/07.php
@@ -0,0 +1,22 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ $query = "CREATE TABLE cats (
+ id SMALLINT NOT NULL AUTO_INCREMENT,
+ family VARCHAR(32) NOT NULL,
+ name VARCHAR(32) NOT NULL,
+ age TINYINT NOT NULL,
+ PRIMARY KEY (id)
+ )";
+
+ $result = $pdo->query($query);
+?>
diff --git a/11/08.php b/11/08.php
new file mode 100644
index 0000000..31f0357
--- /dev/null
+++ b/11/08.php
@@ -0,0 +1,27 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ $query = "DESCRIBE cats";
+ $result = $pdo->query($query);
+
+ echo "| Column | Type | Null | Key |
";
+
+ while ($row = $result->fetch(PDO::FETCH_NUM))
+ {
+ echo "";
+ for ($k = 0 ; $k < 4 ; ++$k)
+ echo "| " . htmlspecialchars($row[$k]) . " | ";
+ echo "
";
+ }
+
+ echo "
";
+?>
diff --git a/11/09.php b/11/09.php
new file mode 100644
index 0000000..b8e665c
--- /dev/null
+++ b/11/09.php
@@ -0,0 +1,15 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ $query = "DROP TABLE cats";
+ $result = $pdo->query($query);
+?>
diff --git a/11/10.php b/11/10.php
new file mode 100644
index 0000000..8f16b2c
--- /dev/null
+++ b/11/10.php
@@ -0,0 +1,19 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ $query = "INSERT INTO cats VALUES(NULL, 'Lion', 'Leo', 4)";
+ $result = $pdo->query($query);
+ $query = "INSERT INTO cats VALUES(NULL, 'Cougar', 'Growler', 2)";
+ $result = $pdo->query($query);
+ $query = "INSERT INTO cats VALUES(NULL, 'Cheetah', 'Charly', 3)";
+ $result = $pdo->query($query);
+?>
diff --git a/11/11.php b/11/11.php
new file mode 100644
index 0000000..02bd42a
--- /dev/null
+++ b/11/11.php
@@ -0,0 +1,27 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ $query = "SELECT * FROM cats";
+ $result = $pdo->query($query);
+
+ echo " | Id | Family | Name | Age |
";
+
+ while ($row = $result->fetch(PDO::FETCH_NUM))
+ {
+ echo "";
+ for ($k = 0 ; $k < 4 ; ++$k)
+ echo "| " . htmlspecialchars($row[$k]) . " | ";
+ echo "
";
+ }
+
+ echo "
";
+?>
diff --git a/11/12.php b/11/12.php
new file mode 100644
index 0000000..d37392d
--- /dev/null
+++ b/11/12.php
@@ -0,0 +1,15 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ $query = "UPDATE cats SET name='Charlie' WHERE name='Charly'";
+ $result = $pdo->query($query);
+?>
diff --git a/11/13.php b/11/13.php
new file mode 100644
index 0000000..404dea5
--- /dev/null
+++ b/11/13.php
@@ -0,0 +1,15 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ $query = "DELETE FROM cats WHERE name='Growler'";
+ $result = $pdo->query($query);
+?>
diff --git a/11/14.php b/11/14.php
new file mode 100644
index 0000000..1a7d7f4
--- /dev/null
+++ b/11/14.php
@@ -0,0 +1,17 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ $query = "INSERT INTO cats VALUES(NULL, 'Lynx', 'Stumpy', 5)";
+ $result = $pdo->query($query);
+
+ echo "The Insert ID was: " . $pdo->lastInsertId();
+?>
diff --git a/11/15.php b/11/15.php
new file mode 100644
index 0000000..a51ff7e
--- /dev/null
+++ b/11/15.php
@@ -0,0 +1,32 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ $query = "SELECT * FROM customers";
+ $result = $pdo->query($query);
+
+ while ($row = $result->fetch())
+ {
+ $custname = htmlspecialchars($row['name']);
+ $custisbn = htmlspecialchars($row['isbn']);
+
+ echo "$custname purchased ISBN $custisbn:
";
+
+ $subquery = "SELECT * FROM classics WHERE isbn='$custisbn'";
+ $subresult = $pdo->query($subquery);
+ $subrow = $subresult->fetch();
+
+ $custbook = htmlspecialchars($subrow['title']);
+ $custauth = htmlspecialchars($subrow['author']);
+
+ echo " '$custbook' by $custauth
";
+ }
+?>
diff --git a/11/16.php b/11/16.php
new file mode 100644
index 0000000..3b569d8
--- /dev/null
+++ b/11/16.php
@@ -0,0 +1,7 @@
+quote($string);
+ }
+?>
diff --git a/11/17.php b/11/17.php
new file mode 100644
index 0000000..f3d0bd6
--- /dev/null
+++ b/11/17.php
@@ -0,0 +1,24 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ $user = mysql_fix_string($pdo, $_POST['user']);
+ $pass = mysql_fix_string($pdo, $_POST['pass']);
+ $query = "SELECT * FROM users WHERE user=$user AND pass=$pass";
+
+ // Etc...
+
+ function mysql_fix_string($pdo, $string)
+ {
+ if (get_magic_quotes_gpc()) $string = stripslashes($string);
+ return $pdo->quote($string);
+ }
+?>
diff --git a/11/18.sql b/11/18.sql
new file mode 100644
index 0000000..9aa95c9
--- /dev/null
+++ b/11/18.sql
@@ -0,0 +1,10 @@
+PREPARE statement FROM "INSERT INTO classics VALUES(?,?,?,?,?)";
+
+SET @author = "Emily Brontë",
+ @title = "Wuthering Heights",
+ @category = "Classic Fiction",
+ @year = "1847",
+ @isbn = "9780553212587";
+
+EXECUTE statement USING @author,@title,@category,@year,@isbn;
+DEALLOCATE PREPARE statement;
diff --git a/11/19.php b/11/19.php
new file mode 100644
index 0000000..2451208
--- /dev/null
+++ b/11/19.php
@@ -0,0 +1,28 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ $stmt = $pdo->prepare('INSERT INTO classics VALUES(?,?,?,?,?)');
+ $stmt->bindParam(1, $author, PDO::PARAM_STR, 128);
+ $stmt->bindParam(2, $title, PDO::PARAM_STR, 128);
+ $stmt->bindParam(3, $category, PDO::PARAM_STR, 16 );
+ $stmt->bindParam(4, $year, PDO::PARAM_INT );
+ $stmt->bindParam(5, $isbn, PDO::PARAM_STR, 13 );
+
+ $author = 'Emily Brontë';
+ $title = 'Wuthering Heights';
+ $category = 'Classic Fiction';
+ $year = '1847';
+ $isbn = '9780553212587';
+
+ $stmt->execute([$author, $title, $category, $year, $isbn]);
+ printf("%d Row inserted.\n", $stmt->rowCount());
+?>
diff --git a/11/20.php b/11/20.php
new file mode 100644
index 0000000..68da3e0
--- /dev/null
+++ b/11/20.php
@@ -0,0 +1,12 @@
+real_escape_string($string);
+ }
+?>
diff --git a/11/21.php b/11/21.php
new file mode 100644
index 0000000..b8c09b9
--- /dev/null
+++ b/11/21.php
@@ -0,0 +1,29 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ $user = mysql_entities_fix_string($pdo, $_POST['user']);
+ $pass = mysql_entities_fix_string($pdo, $_POST['pass']);
+ $query = "SELECT * FROM users WHERE user='$user' AND pass='$pass'";
+
+ //Etc…
+
+ function mysql_entities_fix_string($pdo, $string)
+ {
+ return htmlentities(mysql_fix_string($pdo, $string));
+ }
+
+ function mysql_fix_string($pdo, $string)
+ {
+ if (get_magic_quotes_gpc()) $string = stripslashes($string);
+ return $pdo->quote($string);
+ }
+?>
diff --git a/11/login.php b/11/login.php
new file mode 100644
index 0000000..31a2bed
--- /dev/null
+++ b/11/login.php
@@ -0,0 +1,14 @@
+ PDO::ERRMODE_EXCEPTION,
+ PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
+ PDO::ATTR_EMULATE_PREPARES => false,
+ ];
+?>
diff --git a/11/sqltest.php b/11/sqltest.php
new file mode 100644
index 0000000..4676b6b
--- /dev/null
+++ b/11/sqltest.php
@@ -0,0 +1,78 @@
+getMessage(), (int)$e->getCode());
+ }
+
+ if (isset($_POST['delete']) && isset($_POST['isbn']))
+ {
+ $isbn = get_post($pdo, 'isbn');
+ $query = "DELETE FROM classics WHERE isbn=$isbn";
+ $result = $pdo->query($query);
+ }
+
+ if (isset($_POST['author']) &&
+ isset($_POST['title']) &&
+ isset($_POST['category']) &&
+ isset($_POST['year']) &&
+ isset($_POST['isbn']))
+ {
+ $author = get_post($pdo, 'author');
+ $title = get_post($pdo, 'title');
+ $category = get_post($pdo, 'category');
+ $year = get_post($pdo, 'year');
+ $isbn = get_post($pdo, 'isbn');
+
+ $query = "INSERT INTO classics VALUES" .
+ "($author, $title, $category, $year, $isbn)";
+ $result = $pdo->query($query);
+ }
+
+ echo <<<_END
+
+_END;
+
+ $query = "SELECT * FROM classics";
+ $result = $pdo->query($query);
+
+ while ($row = $result->fetch())
+ {
+ $r0 = htmlspecialchars($row['author']);
+ $r1 = htmlspecialchars($row['title']);
+ $r2 = htmlspecialchars($row['category']);
+ $r3 = htmlspecialchars($row['year']);
+ $r4 = htmlspecialchars($row['isbn']);
+
+ echo <<<_END
+
+ Author $r0
+ Title $r1
+ Category $r2
+ Year $r3
+ ISBN $r4
+
+
+_END;
+ }
+
+ function get_post($pdo, $var)
+ {
+ return $pdo->quote($_POST[$var]);
+ }
+?>
\ No newline at end of file
diff --git a/12/01.php b/12/01.php
new file mode 100644
index 0000000..c6c8265
--- /dev/null
+++ b/12/01.php
@@ -0,0 +1,16 @@
+
+
+ Form Test
+
+
+
+
+