The University of Texas at El Paso - UTEP



3-5<?php $oxo = array(array('x', ' ', 'o'), array('o', 'o', 'x'), array('x', 'o', ' ')); echo $oxo[1][2];?>3-9<?php $author = "Scott Adams"; $out = <<<_END Normal people believe that if it ain’t broke, don’t fix it. Engineers believe that if it ain’t broke, it doesn’t have enough features yet. - $author._END;?>3-10<?php $number = 12345 * 67890; echo substr($number, 3, 1);?><?php $number = 12345 * 67890; echo substr($number, 3, 1);?>3-12<?php function longdate($timestamp) { return date("l F jS Y", $timestamp); }?>3-13<?php function longdate($timestamp) { $temp = date("l F jS Y", $timestamp); return "The date is $temp"; }?>3-14<?php $temp = "The date is "; echo longdate(time()); function longdate($timestamp) { return $temp . date("l F jS Y", $timestamp); }?>3-15<?php $temp = "The date is "; echo $temp . longdate(time()); function longdate($timestamp) { return date("l F jS Y", $timestamp); }?>3-16<?php $temp = "The date is "; echo longdate($temp, time()); function longdate($text, $timestamp) { return $text . date("l F jS Y", $timestamp); }?>3-18<?php static $int = 0; // Allowed static $int = 1+2; // Disallowed (will produce a Parse error) static $int = sqrt(144); // Disallowed?>4-3<?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?>4-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; }?>5-2<?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; }?>5-4<?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)); }?>5-8<?php require_once("library.php"); // Your code goes here?>6-5<?php $p1 = array("Copier", "Inkjet", "Laser", "Photo"); echo "p1 element: " . $p1[2] . "<br>"; $p2 = array('copier' => "Copier & Multipurpose", 'inkjet' => "Inkjet Printer", 'laser' => "Laser Printer", 'photo' => "Photographic Paper"); echo "p2 element: " . $p2['inkjet'] . "<br>";?>6-6<?php $paper = array("Copier", "Inkjet", "Laser", "Photo"); $j = 0; foreach($paper as $item) { echo "$j: $item<br>"; ++$j; }?>6-7<?php $paper = array('copier' => "Copier & Multipurpose", 'inkjet' => "Inkjet Printer", 'laser' => "Laser Printer", 'photo' => "Photographic Paper"); foreach($paper as $item => $description) echo "$item: $description<br>";?>8-3CREATE TABLE classics ( author VARCHAR(128), title VARCHAR(128), type VARCHAR(16), year CHAR(4)) ENGINE InnoDB;8-4USE publications;CREATE TABLE classics (author VARCHAR(128),title VARCHAR(128),type VARCHAR(16),year CHAR(4)) ENGINE InnoDB;DESCRIBE classics;10-1<?php // login.php $hn = 'localhost'; $db = 'publications'; $un = 'username'; // Change this $pw = 'password'; // Change this?>10-4<?php // query.php require_once 'login.php'; $conn = new mysqli($hn, $un, $pw, $db); if ($conn->connect_error) die("Fatal Error"); $query = "SELECT * FROM classics"; $result = $conn->query($query); if (!$result) die("Fatal Error"); $rows = $result->num_rows; for ($j = 0 ; $j < $rows ; ++$j) { $result->data_seek($j); echo 'Author: ' . htmlspecialchars($result->fetch_assoc()['author']) . '<br>'; $result->data_seek($j); echo 'Title: ' . htmlspecialchars($result->fetch_assoc()['title']) . '<br>'; $result->data_seek($j); echo 'Category: '. htmlspecialchars($result->fetch_assoc()['category']). '<br>'; $result->data_seek($j); echo 'Year: ' . htmlspecialchars($result->fetch_assoc()['year']) . '<br>'; $result->data_seek($j); echo 'ISBN: ' . htmlspecialchars($result->fetch_assoc()['isbn']) . '<br><br>'; } $result->close(); $conn->close();?>10-6<?php // sqltest.php require_once 'login.php'; $conn = new mysqli($hn, $un, $pw, $db); if ($conn->connect_error) die("Fatal Error"); if (isset($_POST['delete']) && isset($_POST['isbn'])) { $isbn = get_post($conn, 'isbn'); $query = "DELETE FROM classics WHERE isbn='$isbn'"; $result = $conn->query($query); if (!$result) echo "DELETE failed<br><br>"; } if (isset($_POST['author']) && isset($_POST['title']) && isset($_POST['category']) && isset($_POST['year']) && isset($_POST['isbn'])) { $author = get_post($conn, 'author'); $title = get_post($conn, 'title'); $category = get_post($conn, 'category'); $year = get_post($conn, 'year'); $isbn = get_post($conn, 'isbn'); $query = "INSERT INTO classics VALUES" . "('$author', '$title', '$category', '$year', '$isbn')"; $result = $conn->query($query); if (!$result) echo "INSERT failed<br><br>"; } echo <<<_END <form action="sqltest.php" method="post"><pre> Author <input type="text" name="author"> Title <input type="text" name="title"> Category <input type="text" name="category"> Year <input type="text" name="year"> ISBN <input type="text" name="isbn"> <input type="submit" value="ADD RECORD"> </pre></form>_END; $query = "SELECT * FROM classics"; $result = $conn->query($query); if (!$result) die ("Database access failed"); $rows = $result->num_rows; for ($j = 0 ; $j < $rows ; ++$j) { $row = $result->fetch_array(MYSQLI_NUM); $r0 = htmlspecialchars($row[0]); $r1 = htmlspecialchars($row[1]); $r2 = htmlspecialchars($row[2]); $r3 = htmlspecialchars($row[3]); $r4 = htmlspecialchars($row[4]); echo <<<_END <pre> Author $r0 Title $r1 Category $r2 Year $r3 ISBN $r4 </pre> <form action='sqltest.php' method='post'> <input type='hidden' name='delete' value='yes'> <input type='hidden' name='isbn' value='$r4'> <input type='submit' value='DELETE RECORD'></form>_END; } $result->close(); $conn->close(); function get_post($conn, $var) { return $conn->real_escape_string($_POST[$var]); }?> ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download