Updated files

This commit is contained in:
RobinNixon
2021-04-18 11:18:28 +01:00
parent aefe77f6e8
commit f63a81074d
187 changed files with 1694 additions and 254 deletions
+2 -2
View File
@@ -5,8 +5,8 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
?>
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$query = "SELECT * FROM classics";
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$query = "SELECT * FROM classics";
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
if (isset($_POST['delete']) && isset($_POST['isbn']))
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$query = "CREATE TABLE cats (
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$query = "DESCRIBE cats";
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$query = "DROP TABLE cats";
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$query = "INSERT INTO cats VALUES(NULL, 'Lion', 'Leo', 4)";
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$query = "SELECT * FROM cats";
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$query = "UPDATE cats SET name='Charlie' WHERE name='Charly'";
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$query = "DELETE FROM cats WHERE name='Growler'";
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$query = "INSERT INTO cats VALUES(NULL, 'Lynx', 'Stumpy', 5)";
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$query = "SELECT * FROM customers";
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$user = mysql_fix_string($pdo, $_POST['user']);
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$stmt = $pdo->prepare('INSERT INTO classics VALUES(?,?,?,?,?)');
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
$user = mysql_entities_fix_string($pdo, $_POST['user']);
+2 -2
View File
@@ -5,9 +5,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
if (isset($_POST['delete']) && isset($_POST['isbn']))
+3 -1
View File
@@ -1,4 +1,6 @@
<script>
days_to_new_year = 366 - day_number;
day_number = 127 // For example
days_to_new_year = 366 - day_number
if (days_to_new_year < 30) document.write("It's nearly New Year")
else document.write("It's a long time to go")
</script>
+4
View File
@@ -1,4 +1,8 @@
<script>
let c = "Car"
displayItems("Bananas", 32.3, c)
function displayItems()
{
for (j = 0 ; j < displayItems.arguments.length ; ++j)
+203
View File
@@ -0,0 +1,203 @@
<?php // adduser.php
// Start with the PHP code
$forename = $surname = $username = $password = $age = $email = "";
if (isset($_POST['forename']))
$forename = fix_string($_POST['forename']);
if (isset($_POST['surname']))
$surname = fix_string($_POST['surname']);
if (isset($_POST['username']))
$username = fix_string($_POST['username']);
if (isset($_POST['password']))
$password = fix_string($_POST['password']);
if (isset($_POST['age']))
$age = fix_string($_POST['age']);
if (isset($_POST['email']))
$email = fix_string($_POST['email']);
$fail = validate_forename($forename);
$fail .= validate_surname($surname);
$fail .= validate_username($username);
$fail .= validate_password($password);
$fail .= validate_age($age);
$fail .= validate_email($email);
echo "<!DOCTYPE html>\n<html><head><title>An Example Form</title>";
if ($fail == "")
{
echo "</head><body>Form data successfully validated:
$forename, $surname, $username, $password, $age, $email.</body></html>";
// This is where you would enter the posted fields into a database,
// preferably using hash encryption for the password.
exit;
}
echo <<<_END
<!-- The HTML/JavaScript section -->
<style>
.signup {
border: 1px solid #999999;
font: normal 14px helvetica; color:#444444;
}
</style>
<script>
function validate(form)
{
fail = validateForename(form.forename.value)
fail += validateSurname(form.surname.value)
fail += validateUsername(form.username.value)
fail += validatePassword(form.password.value)
fail += validateAge(form.age.value)
fail += validateEmail(form.email.value)
if (fail == "") return true
else { alert(fail); return false }
}
function validateForename(field)
{
return (field == "") ? "No Forename was entered.\\n" : ""
}
function validateSurname(field)
{
return (field == "") ? "No Surname was entered.\\n" : ""
}
function validateUsername(field)
{
if (field == "") return "No Username was entered.\\n"
else if (field.length < 5)
return "Usernames must be at least 5 characters.\\n"
else if (/[^a-zA-Z0-9_-]/.test(field))
return "Only a-z, A-Z, 0-9, - and _ allowed in Usernames.\\n"
return ""
}
function validatePassword(field)
{
if (field == "") return "No Password was entered.\\n"
else if (field.length < 6)
return "Passwords must be at least 6 characters.\\n"
else if (!/[a-z]/.test(field) || ! /[A-Z]/.test(field) ||
!/[0-9]/.test(field))
return "Passwords require one each of a-z, A-Z and 0-9.\\n"
return ""
}
function validateAge(field)
{
if (isNaN(field)) return "No Age was entered.\\n"
else if (field < 18 || field > 110)
return "Age must be between 18 and 110.\\n"
return ""
}
function validateEmail(field)
{
if (field == "") return "No Email was entered.\\n"
else if (!((field.indexOf(".") > 0) &&
(field.indexOf("@") > 0)) ||
/[^a-zA-Z0-9.@_-]/.test(field))
return "The Email address is invalid.\\n"
return ""
}
</script>
</head>
<body>
<table border="0" cellpadding="2" cellspacing="5" bgcolor="#eeeeee">
<th colspan="2" align="center">Signup Form</th>
<tr><td colspan="2">Sorry, the following errors were found<br>
in your form: <p><font color=red size=1><i>$fail</i></font></p>
</td></tr>
<form method="post" action="adduser.php" onSubmit="return validate(this)">
<tr><td>Forename</td>
<td><input type="text" maxlength="32" name="forename" value="$forename">
</td></tr><tr><td>Surname</td>
<td><input type="text" maxlength="32" name="surname" value="$surname">
</td></tr><tr><td>Username</td>
<td><input type="text" maxlength="16" name="username" value="$username">
</td></tr><tr><td>Password</td>
<td><input type="text" maxlength="12" name="password" value="$password">
</td></tr><tr><td>Age</td>
<td><input type="text" maxlength="3" name="age" value="$age">
</td></tr><tr><td>Email</td>
<td><input type="text" maxlength="64" name="email" value="$email">
</td></tr><tr><td colspan="2" align="center"><input type="submit"
value="Signup"></td></tr>
</form>
</table>
</body>
</html>
_END;
// The PHP functions
function validate_forename($field)
{
return ($field == "") ? "No Forename was entered<br>": "";
}
function validate_surname($field)
{
return($field == "") ? "No Surname was entered<br>" : "";
}
function validate_username($field)
{
if ($field == "") return "No Username was entered<br>";
else if (strlen($field) < 5)
return "Usernames must be at least 5 characters<br>";
else if (preg_match("/[^a-zA-Z0-9_-]/", $field))
return "Only letters, numbers, - and _ in usernames<br>";
return "";
}
function validate_password($field)
{
if ($field == "") return "No Password was entered<br>";
else if (strlen($field) < 6)
return "Passwords must be at least 6 characters<br>";
else if (!preg_match("/[a-z]/", $field) ||
!preg_match("/[A-Z]/", $field) ||
!preg_match("/[0-9]/", $field))
return "Passwords require 1 each of a-z, A-Z and 0-9<br>";
return "";
}
function validate_age($field)
{
if ($field == "") return "No Age was entered<br>";
else if ($field < 18 || $field > 110)
return "Age must be between 18 and 110<br>";
return "";
}
function validate_email($field)
{
if ($field == "") return "No Email was entered<br>";
else if (!((strpos($field, ".") > 0) &&
(strpos($field, "@") > 0)) ||
preg_match("/[^a-zA-Z0-9.@_-]/", $field))
return "The Email address is invalid<br>";
return "";
}
function fix_string($string)
{
if (get_magic_quotes_gpc()) $string = stripslashes($string);
return htmlentities ($string);
}
?>
+8 -47
View File
@@ -8,58 +8,19 @@
<div id='info'>This sentence will be replaced</div>
<script>
params = "url=news.com"
request = new asyncRequest()
let XHR = new XMLHttpRequest()
request.open("POST", "urlpost.php", true)
request.setRequestHeader("Content-type",
"application/x-www-form-urlencoded")
XHR.open("POST", "http://127.0.0.1/18/urlpost.php", true)
XHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
XHR.send("url=news.com")
request.onreadystatechange = function()
XHR.onreadystatechange = function()
{
if (this.readyState == 4)
if (this.readyState == 4 && this.status == 200)
{
if (this.status == 200)
{
if (this.responseText != null)
{
document.getElementById('info').innerHTML =
this.responseText
}
else alert("Communication error: No data received")
}
else alert( "Communication error: " + this.statusText)
document.getElementById("info").innerHTML = this.responseText
}
}
request.send(params)
function asyncRequest()
{
try
{
var request = new XMLHttpRequest()
}
catch(e1)
{
try
{
request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch(e2)
{
try
{
request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch(e3)
{
request = false
}
}
}
return request
}
}
</script>
</body>
</html>
+10 -45
View File
@@ -8,55 +8,20 @@
<div id='info'>This sentence will be replaced</div>
<script>
nocache = "&nocache=" + Math.random() * 1000000
request = new asyncRequest()
request.open("GET", "urlget.php?url=news.com" + nocache, true)
let nocache = "&nocache=" + Math.random() * 1000000
let XHR = new XMLHttpRequest()
request.onreadystatechange = function()
XHR.open("POST", "http://127.0.0.1/18/urlget.php?url=news.com" + nocache, true)
XHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
XHR.send()
XHR.onreadystatechange = function()
{
if (this.readyState == 4)
if (this.readyState == 4 && this.status == 200)
{
if (this.status == 200)
{
if (this.responseText != null)
{
document.getElementById('info').innerHTML =
this.responseText
}
else alert("Communication error: No data received")
}
else alert( "Communication error: " + this.statusText)
document.getElementById("info").innerHTML = this.responseText
}
}
request.send(null)
function asyncRequest()
{
try
{
var request = new XMLHttpRequest()
}
catch(e1)
{
try
{
request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch(e2)
{
try
{
request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch(e3)
{
request = false
}
}
}
return request
}
}
</script>
</body>
</html>
+17 -52
View File
@@ -8,63 +8,28 @@
<div id='info'>This sentence will be replaced</div>
<script>
nocache = "&nocache=" + Math.random() * 1000000
url = "rss.news.yahoo.com/rss/topstories"
out = "";
let out = ''
let nocache = "&nocache=" + Math.random() * 1000000
let url = "rss.news.yahoo.com/rss/topstories"
let XHR = new XMLHttpRequest()
XHR.open("POST", "http://127.0.0.1/18/xmlget.php?url=" + url + nocache, true)
XHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
XHR.send()
request = new asyncRequest()
request.open("GET", "xmlget.php?url=" + url + nocache, true)
request.onreadystatechange = function()
XHR.onreadystatechange = function()
{
if (this.readyState == 4)
if (this.readyState == 4 && this.status == 200)
{
if (this.status == 200)
{
if (this.responseText != null)
{
titles = this.responseXML.getElementsByTagName('title')
let titles = this.responseXML.getElementsByTagName('title')
for (j = 0 ; j < titles.length ; ++j)
{
out += titles[j].childNodes[0].nodeValue + '<br>'
}
document.getElementById('info').innerHTML = out
}
else alert("Communication error: No data received")
}
else alert( "Communication error: " + this.statusText)
for (let j = 0 ; j < titles.length ; ++j)
{
out += titles[j].childNodes[0].nodeValue + '<br>'
}
document.getElementById('info').innerHTML = out
}
}
request.send(null)
function asyncRequest()
{
try
{
var request = new XMLHttpRequest()
}
catch(e1)
{
try
{
request = new ActiveXObject("Msxml2.XMLHTTP")
}
catch(e2)
{
try
{
request = new ActiveXObject("Microsoft.XMLHTTP")
}
catch(e3)
{
request = false
}
}
}
return request
}
}
</script>
</body>
</html>
+27
View File
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html> <!-- urlget.html -->
<head>
<title>Asynchronous Communication Example</title>
</head>
<body style='text-align:center'>
<h1>Loading a web page into a DIV</h1>
<div id='info'>This sentence will be replaced</div>
<script>
let nocache = "&nocache=" + Math.random() * 1000000
let XHR = new XMLHttpRequest()
XHR.open("POST", "http://127.0.0.1/18/urlget.php?url=news.com" + nocache, true)
XHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
XHR.send()
XHR.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
document.getElementById("info").innerHTML = this.responseText
}
}
</script>
</body>
</html>
+26
View File
@@ -0,0 +1,26 @@
<!DOCTYPE html>
<html> <!-- urlpost.html -->
<head>
<title>Asynchronous Communication Example</title>
</head>
<body style='text-align:center'>
<h1>Loading a web page into a DIV</h1>
<div id='info'>This sentence will be replaced</div>
<script>
let XHR = new XMLHttpRequest()
XHR.open("POST", "http://127.0.0.1/18/urlpost.php", true)
XHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
XHR.send("url=news.com")
XHR.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
document.getElementById("info").innerHTML = this.responseText
}
}
</script>
</body>
</html>
+35
View File
@@ -0,0 +1,35 @@
<!DOCTYPE html>
<html> <!-- xmlget.html -->
<head>
<title>Asynchronous Communication Example</title>
</head>
<body>
<h1>Loading XML data into a DIV</h1>
<div id='info'>This sentence will be replaced</div>
<script>
let out = ''
let nocache = "&nocache=" + Math.random() * 1000000
let url = "rss.news.yahoo.com/rss/topstories"
let XHR = new XMLHttpRequest()
XHR.open("POST", "http://127.0.0.1/18/xmlget.php?url=" + url + nocache, true)
XHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded")
XHR.send()
XHR.onreadystatechange = function()
{
if (this.readyState == 4 && this.status == 200)
{
let titles = this.responseXML.getElementsByTagName('title')
for (let j = 0 ; j < titles.length ; ++j)
{
out += titles[j].childNodes[0].nodeValue + '<br>'
}
document.getElementById('info').innerHTML = out
}
}
</script>
</body>
</html>
+14
View File
@@ -0,0 +1,14 @@
<?php // xmlget.php
if (isset($_GET['url']))
{
header('Content-Type: text/xml');
echo file_get_contents("http://".sanitizeString($_GET['url']));
}
function sanitizeString($var)
{
$var = strip_tags($var);
$var = htmlentities($var);
return stripslashes($var);
}
?>
-18
View File
@@ -19,33 +19,15 @@
border-radius :40px;
}
.b2 {
-moz-border-radius :40px 40px 20px 20px;
-webkit-border-radius:40px 40px 20px 20px;
border-radius :40px 40px 20px 20px;
}
.b3 {
-moz-border-radius-topleft :20px;
-moz-border-radius-topright :40px;
-moz-border-radius-bottomleft :60px;
-moz-border-radius-bottomright :80px;
-webkit-border-top-left-radius :20px;
-webkit-border-top-right-radius :40px;
-webkit-border-bottom-left-radius :60px;
-webkit-border-bottom-right-radius:80px;
border-top-left-radius :20px;
border-top-right-radius :40px;
border-bottom-left-radius :60px;
border-bottom-right-radius :80px;
}
.b4 {
-moz-border-radius-topleft :40px 20px;
-moz-border-radius-topright :40px 20px;
-moz-border-radius-bottomleft :20px 40px;
-moz-border-radius-bottomright :20px 40px;
-webkit-border-top-left-radius :40px 20px;
-webkit-border-top-right-radius :40px 20px;
-webkit-border-bottom-left-radius :20px 40px;
-webkit-border-bottom-right-radius:20px 40px;
border-top-left-radius :40px 20px;
border-top-right-radius :40px 20px;
border-bottom-left-radius :20px 40px;
-6
View File
@@ -6,12 +6,6 @@
.columns {
text-align :justify;
font-size :16pt;
-moz-column-count :3;
-moz-column-gap :1em;
-moz-column-rule :1px solid black;
-webkit-column-count:3;
-webkit-column-gap :1em;
-webkit-column-rule :1px solid black;
column-count :3;
column-gap :1em;
column-rule :1px solid black;
-8
View File
@@ -15,17 +15,9 @@
border-style :solid;
background :orange;
transition :all .8s ease-in-out;
-moz-transition :all .8s ease-in-out;
-webkit-transition:all .8s ease-in-out;
-o-transition :all .8s ease-in-out;
-ms-transition :all .8s ease-in-out;
}
#square:hover {
background :yellow;
-moz-transform :rotate(180deg);
-webkit-transform :rotate(180deg);
-o-transform :rotate(180deg);
-ms-transform :rotate(180deg);
transform :rotate(180deg);
}
</style>
+8 -7
View File
@@ -12,18 +12,19 @@
newdiv = document.createElement('div')
newdiv.id = 'NewDiv'
document.body.appendChild(newdiv)
document.body.append(newdiv)
S(newdiv).border = 'solid 1px red'
S(newdiv).width = '100px'
S(newdiv).height = '100px'
newdiv.innerHTML = "I'm a new object inserted in the DOM"
tmp = newdiv.offsetTop
alert('Click OK to remove the element')
pnode = newdiv.parentNode
pnode.removeChild(newdiv)
tmp = pnode.offsetTop
setTimeout(function()
{
alert('Click OK to remove the element')
newdiv.parentNode.removeChild(newdiv)
}, 1000)
</script>
</body>
</html>
+15 -16
View File
@@ -19,26 +19,25 @@
return degrees * Math.PI / 180
}
// Following is the original example code
//
// arcs =
// [
// Math.PI,
// Math.PI * 2,
// Math.PI / 2,
// Math.PI / 180 * 59
// ]
//
// Below the code now uses degrees as arguments
arcs =
[
Math.degreesToRadians(180),
Math.degreesToRadians(360),
Math.degreesToRadians(90),
Math.degreesToRadians(59)
Math.PI,
Math.PI * 2,
Math.PI / 2,
Math.PI / 180 * 59
]
// This code below uses degrees as arguments as shown
// later in the chapter
// arcs =
// [
// Math.degreesToRadians(180),
// Math.degreesToRadians(360),
// Math.degreesToRadians(90),
// Math.degreesToRadians(59)
// ]
for (j = 0 ; j < 4 ; ++j)
{
context.beginPath()
+10 -10
View File
@@ -1,8 +1,8 @@
<?php // Example 01: functions.php
$host = 'localhost'; // Change as necessary
$data = 'publications'; // Change as necessary
$user = 'root'; // Change as necessary
$pass = 'mysql'; // Change as necessary
$data = 'robinsnest'; // Change as necessary
$user = 'robinsnest'; // Change as necessary
$pass = 'password'; // Change as necessary
$chrs = 'utf8mb4';
$attr = "mysql:host=$host;dbname=$data;charset=$chrs";
$opts =
@@ -16,9 +16,9 @@
{
$pdo = new PDO($attr, $user, $pass, $opts);
}
catch (\PDOException $e)
catch (PDOException $e)
{
throw new \PDOException($e->getMessage(), (int)$e->getCode());
throw new PDOException($e->getMessage(), (int)$e->getCode());
}
function createTable($name, $query)
@@ -59,13 +59,13 @@
if (file_exists("$user.jpg"))
echo "<img src='$user.jpg' style='float:left;'>";
$result = queryMysql("SELECT * FROM profiles WHERE user='$user'");
$result = $pdo->query("SELECT * FROM profiles WHERE user='$user'");
if ($result->rowCount())
while ($row = $result->fetch())
{
$row = $result->fetch();
echo stripslashes($row['text']) . "<br style='clear:left;'><br>";
die(stripslashes($row['text']) . "<br style='clear:left;'><br>");
}
else echo "<p>Nothing to see here, yet</p><br>";
echo "<p>Nothing to see here, yet</p><br>";
}
?>
+4
View File
@@ -0,0 +1,4 @@
<?php
echo "Hello world";
?>
+6
View File
@@ -0,0 +1,6 @@
<?php
/* This is a section
of multi-line comments
which will not be
interpreted */
?>
+5
View File
@@ -0,0 +1,5 @@
<?php
$mycounter = 1;
$mystring = "Hello";
$myarray = array("One", "Two", "Three");
?>
+7
View File
@@ -0,0 +1,7 @@
<?php // test1.php
$username = "Fred Smith";
echo $username;
echo "<br>";
$current_user = $username;
echo $current_user;
?>
+7
View File
@@ -0,0 +1,7 @@
<?php
$oxo = array(array('x', ' ', 'o'),
array('o', 'o', 'x'),
array('x', 'o', ' '));
echo $oxo[1][2];
?>
+8
View File
@@ -0,0 +1,8 @@
<?php
$author = "Steve Ballmer";
echo "Developers, Developers, developers, developers, developers,
developers, developers, developers, developers!
- $author.";
?>
+10
View File
@@ -0,0 +1,10 @@
<?php
$author = "Bill Gates";
$text = "Measuring programming progress by lines of code is like
Measuring aircraft building progress by weight.
- $author.";
echo $text;
?>
+11
View File
@@ -0,0 +1,11 @@
<?php
$author = "Brian W. Kernighan";
echo <<<_END
Debugging is twice as hard as writing the code in the first place.
Therefore, if you write the code as cleverly as possible, you are,
by definition, not smart enough to debug it.
- $author.
_END;
?>
+11
View File
@@ -0,0 +1,11 @@
<?php
$author = "Scott Adams";
$out = <<<_END
Normal people believe that if it aint broke, dont fix it.
Engineers believe that if it aint broke, it doesnt have enough
features yet.
- $author.
_END;
?>
+4
View File
@@ -0,0 +1,4 @@
<?php
$number = 12345 * 67890;
echo substr($number, 3, 1);
?>
+5
View File
@@ -0,0 +1,5 @@
<?php
$pi = "3.1415927";
$radius = 5;
echo $pi * ($radius * $radius);
?>
+6
View File
@@ -0,0 +1,6 @@
<?php
function longdate($timestamp)
{
return date("l F jS Y", $timestamp);
}
?>
+7
View File
@@ -0,0 +1,7 @@
<?php
function longdate($timestamp)
{
$temp = date("l F jS Y", $timestamp);
return "The date is $temp";
}
?>
+9
View File
@@ -0,0 +1,9 @@
<?php
$temp = "The date is ";
echo longdate(time());
function longdate($timestamp)
{
return $temp . date("l F jS Y", $timestamp);
}
?>
+9
View File
@@ -0,0 +1,9 @@
<?php
$temp = "The date is ";
echo $temp . longdate(time());
function longdate($timestamp)
{
return date("l F jS Y", $timestamp);
}
?>
+9
View File
@@ -0,0 +1,9 @@
<?php
$temp = "The date is ";
echo longdate($temp, time());
function longdate($text, $timestamp)
{
return $text . date("l F jS Y", $timestamp);
}
?>
+13
View File
@@ -0,0 +1,13 @@
<?php
echo test();
echo "<br><br>";
echo test();
function test()
{
static $count = 0;
echo $count;
$count++;
}
?>
+5
View File
@@ -0,0 +1,5 @@
<?php
static $int = 0; // Allowed
static $int = 1+2; // Disallowed (will produce a Parse error)
static $int = sqrt(144); // Disallowed
?>
+6
View File
@@ -0,0 +1,6 @@
<?php
echo "a: [" . (20 > 9) . "]<br>";
echo "b: [" . (5 == 6) . "]<br>";
echo "c: [" . (1 == 0) . "]<br>";
echo "d: [" . (1 == 1) . "]<br>";
?>
+4
View File
@@ -0,0 +1,4 @@
<?php // test2.php
echo "a: [" . TRUE . "]<br>";
echo "b: [" . FALSE . "]<br>";
?>
+10
View File
@@ -0,0 +1,10 @@
<?php
$myname = "Brian";
$myage = 37;
echo "a: " . 73 . "<br>"; // Numeric literal
echo "b: " . "Hello" . "<br>"; // String literal
echo "c: " . FALSE . "<br>"; // Constant literal
echo "d: " . $myname . "<br>"; // String variable
echo "e: " . $myage . "<br>"; // Numeric variable
?>
+9
View File
@@ -0,0 +1,9 @@
<?php
$day_number = 340; // Assignment by Value
$days_to_new_year = 366 - $day_number; // Assignment by Expression
if ($days_to_new_year < 30) // Condition
{
echo "Not long now till new year"; // Statement
}
?>
+3
View File
@@ -0,0 +1,3 @@
<?php
$level = $score = $time = 0;
?>
+5
View File
@@ -0,0 +1,5 @@
<?php
$month = "March";
if ($month == "March") echo "It's springtime";
?>
+7
View File
@@ -0,0 +1,7 @@
<?php
$a = "1000";
$b = "+1000";
if ($a == $b) echo "1";
if ($a === $b) echo "2";
?>
+7
View File
@@ -0,0 +1,7 @@
<?php
$a = "1000";
$b = "+1000";
if ($a != $b) echo "1";
if ($a !== $b) echo "2";
?>
+7
View File
@@ -0,0 +1,7 @@
<?php
$a = 2; $b = 3;
if ($a > $b) echo "$a is greater than $b<br>";
if ($a < $b) echo "$a is less than $b<br>";
if ($a >= $b) echo "$a is greater than or equal to $b<br>";
if ($a <= $b) echo "$a is less than or equal to $b<br>";
?>
+8
View File
@@ -0,0 +1,8 @@
<?php
$a = 1; $b = 0;
echo ($a AND $b) . "<br>";
echo ($a or $b) . "<br>";
echo ($a XOR $b) . "<br>";
echo !$a . "<br>";
?>
+3
View File
@@ -0,0 +1,3 @@
<?php
if ($finished == 1 or getnext() == 1) exit;
?>
+5
View File
@@ -0,0 +1,5 @@
<?php
$gn = getnext();
if ($finished == 1 or $gn == 1) exit;
?>
+7
View File
@@ -0,0 +1,7 @@
<?php
if ($bank_balance < 100)
{
$money = 1000;
$bank_balance += $money;
}
?>
+12
View File
@@ -0,0 +1,12 @@
<?php
if ($bank_balance < 100)
{
$money = 1000;
$bank_balance += $money;
}
else
{
$savings += 50;
$bank_balance -= 50;
}
?>
+17
View File
@@ -0,0 +1,17 @@
<?php
if ($bank_balance < 100)
{
$money = 1000;
$bank_balance += $money;
}
elseif ($bank_balance > 200)
{
$savings += 100;
$bank_balance -= 100;
}
else
{
$savings += 50;
$bank_balance -= 50;
}
?>
+10
View File
@@ -0,0 +1,10 @@
<?php
$page = "test";
if ($page == "Home") echo "You selected Home";
elseif ($page == "About") echo "You selected About";
elseif ($page == "News") echo "You selected News";
elseif ($page == "Login") echo "You selected Login";
elseif ($page == "Links") echo "You selected Links";
else echo "Unrecognized selection";
?>
+15
View File
@@ -0,0 +1,15 @@
<?php
switch ($page)
{
case "Home": echo "You selected Home";
break;
case "About": echo "You selected About";
break;
case "News": echo "You selected News";
break;
case "Login": echo "You selected Login";
break;
case "Links": echo "You selected Links";
break;
}
?>
+23
View File
@@ -0,0 +1,23 @@
<?php
switch ($page)
{
case "Home":
echo "You selected Home";
break;
case "About":
echo "You selected About";
break;
case "News":
echo "You selected News";
break;
case "Login":
echo "You selected Login";
break;
case "Links":
echo "You selected Links";
break;
default:
echo "Unrecognized selection";
break;
}
?>
+13
View File
@@ -0,0 +1,13 @@
<?php
switch ($page):
case "Home":
echo "You selected Home";
break;
// etc...
case "Links":
echo "You selected Links";
break;
endswitch;
?>
+3
View File
@@ -0,0 +1,3 @@
<?php
echo $fuel <= 1 ? "Fill tank now" : "There's enough fuel";
?>
+3
View File
@@ -0,0 +1,3 @@
<?php
$enough = $fuel <= 1 ? FALSE : TRUE;
?>
+9
View File
@@ -0,0 +1,9 @@
<?php
$fuel = 10;
while ($fuel > 1)
{
// Keep driving …
echo "There's enough fuel";
}
?>
+9
View File
@@ -0,0 +1,9 @@
<?php
$count = 1;
while ($count <= 12)
{
echo "$count times 12 is " . $count * 12 . "<br>";
++$count;
}
?>
+6
View File
@@ -0,0 +1,6 @@
<?php
$count = 0;
while (++$count <= 12)
echo "$count times 12 is " . $count * 12 . "<br>";
?>
+7
View File
@@ -0,0 +1,7 @@
<?php
$count = 1;
do
echo "$count times 12 is " . $count * 12 . "<br>";
while (++$count <= 12);
?>
+8
View File
@@ -0,0 +1,8 @@
<?php
$count = 1;
do {
echo "$count times 12 is " . $count * 12;
echo "<br>";
} while (++$count <= 12);
?>
+4
View File
@@ -0,0 +1,4 @@
<?php
for ($count = 1 ; $count <= 12 ; ++$count)
echo "$count times 12 is " . $count * 12 . "<br>";
?>
+7
View File
@@ -0,0 +1,7 @@
<?php
for ($count = 1 ; $count <= 12 ; ++$count)
{
echo "$count times 12 is " . $count * 12;
echo "<br>";
}
?>
+12
View File
@@ -0,0 +1,12 @@
<?php
$fp = fopen("text.txt", 'wb');
for ($j = 0 ; $j < 100 ; ++$j)
{
$written = fwrite($fp, "data");
if ($written == FALSE) break;
}
fclose($fp);
?>
+12
View File
@@ -0,0 +1,12 @@
<?php
$j = 10;
while ($j > -10)
{
$j--;
if ($j == 0) continue;
echo (10 / $j) . "<br>";
}
?>
+7
View File
@@ -0,0 +1,7 @@
<?php
$a = 56;
$b = 12;
$c = $a / $b;
echo $c;
?>
+5
View File
@@ -0,0 +1,5 @@
<?php
echo strrev(" .dlrow olleH"); // Reverse string
echo str_repeat("Hip ", 2); // Repeat string
echo strtoupper("hooray!"); // String to upper case
?>
+12
View File
@@ -0,0 +1,12 @@
<?php
echo fix_names("WILLIAM", "henry", "gatES");
function fix_names($n1, $n2, $n3)
{
$n1 = ucfirst(strtolower($n1));
$n2 = ucfirst(strtolower($n2));
$n3 = ucfirst(strtolower($n3));
return $n1 . " " . $n2 . " " . $n3;
}
?>
+13
View File
@@ -0,0 +1,13 @@
<?php
$names = fix_names("WILLIAM", "henry", "gatES");
echo $names[0] . " " . $names[1] . " " . $names[2];
function fix_names($n1, $n2, $n3)
{
$n1 = ucfirst(strtolower($n1));
$n2 = ucfirst(strtolower($n2));
$n3 = ucfirst(strtolower($n3));
return array($n1, $n2, $n3);
}
?>
+16
View File
@@ -0,0 +1,16 @@
<?php
$a1 = "WILLIAM";
$a2 = "henry";
$a3 = "gatES";
echo $a1 . " " . $a2 . " " . $a3 . "<br>";
fix_names($a1, $a2, $a3);
echo $a1 . " " . $a2 . " " . $a3;
function fix_names(&$n1, &$n2, &$n3)
{
$n1 = ucfirst(strtolower($n1));
$n2 = ucfirst(strtolower($n2));
$n3 = ucfirst(strtolower($n3));
}
?>
+16
View File
@@ -0,0 +1,16 @@
<?php
$a1 = "WILLIAM";
$a2 = "henry";
$a3 = "gatES";
echo $a1 . " " . $a2 . " " . $a3 . "<br>";
fix_names();
echo $a1 . " " . $a2 . " " . $a3;
function fix_names()
{
global $a1; $a1 = ucfirst(strtolower($a1));
global $a2; $a2 = ucfirst(strtolower($a2));
global $a3; $a3 = ucfirst(strtolower($a3));
}
?>
+6
View File
@@ -0,0 +1,6 @@
<?php
include("library.php");
// Your code goes here
?>
+7
View File
@@ -0,0 +1,7 @@
<?php
include_once("library.php");
// Your code goes here
?>
+5
View File
@@ -0,0 +1,5 @@
<?php
require_once("library.php");
// Your code goes here
?>
+10
View File
@@ -0,0 +1,10 @@
<?php
if (function_exists("array_combine"))
{
echo "Function exists";
}
else
{
echo "Function does not exist - better write our own";
}
?>
+14
View File
@@ -0,0 +1,14 @@
<?php
$object = new User;
print_r($object);
class User
{
public $name, $password;
function save_user()
{
echo "Save User code goes here";
}
}
?>
+20
View File
@@ -0,0 +1,20 @@
<?php
$object = new User;
print_r($object); echo "<br>";
$object->name = "Joe";
$object->password = "mypass";
print_r($object); echo "<br>";
$object->save_user();
class User
{
public $name, $password;
function save_user()
{
echo "Save User code goes here";
}
}
?>
+14
View File
@@ -0,0 +1,14 @@
<?php
$object1 = new User();
$object1->name = "Alice";
$object2 = $object1;
$object2->name = "Amy";
echo "object1 name = " . $object1->name . "<br>";
echo "object2 name = " . $object2->name;
class User
{
public $name;
}
?>
+14
View File
@@ -0,0 +1,14 @@
<?php
$object1 = new User();
$object1->name = "Alice";
$object2 = clone $object1;
$object2->name = "Amy";
echo "object1 name = " . $object1->name . "<br>";
echo "object2 name = " . $object2->name;
class User
{
public $name;
}
?>
+9
View File
@@ -0,0 +1,9 @@
<?php
class User
{
function __construct($param1, $param2)
{
// Constructor statements go here
}
}
?>
+9
View File
@@ -0,0 +1,9 @@
<?php
class Test
{
public $name = "Paul Smith"; // Valid
public $age = 42; // Valid
public $time = time(); // Invalid - calls a function
public $score = $level * 2; // Invalid - uses an expression
}
?>
+10
View File
@@ -0,0 +1,10 @@
<?php
class User
{
public $name, $password;
function get_password()
{
return $this->password;
}
?>
+8
View File
@@ -0,0 +1,8 @@
<?php
$object1 = new User();
$object1->name = "Alice";
echo $object1->name;
class User {}
?>
+9
View File
@@ -0,0 +1,9 @@
<?php
class Test
{
public $name = "Paul Smith"; // Valid
public $age = 42; // Valid
public $time = time(); // Invalid - calls a function
public $score = $level * 2; // Invalid - uses an expression
}
?>

Some files were not shown because too many files have changed in this diff Show More