Except where otherwise noted, the contents of this document are Copyright © Marty Stepp, Jessica Miller, and Victoria Kirst. All rights reserved. Any redistribution, reproduction, transmission, or storage of part or all of the contents in any form is prohibited without the author's expressed written permission.
Write the JS code to connect to a server-side JSON address book called
addressbook.php
.
Start from this HTML.
(sample solution)
(solution)
addressbook.php
with no parameters outputs an array of names:
{"names": ["Suzie", "Billy", ...]}
name
parameter outputs that person's address:
{"name": "Billy", "address": "123 4th St."}
name
and address
parameter saves that person in the address book.
POST
requestvar params = new FormData(); params.append("name", value); params.append("name", value); var ajax = new XMLHttpRequest(); ajax.onload = functionName; ajax.open("POST", "url", true); ajax.send(params);
Given 5 image files (kittie1.jpg, kittie2.jpg, etc.), write a PHP page that displays all 5 images as seen here (view source on output to get starter code!).
<!DOCTYPE html> <html> <head> <title>kitties</title> </head> <body> <div> <?php for ($i = 1; $i <= 5; $i++) { ?> <img src="kittie<?= $i ?>.jpg" /> <?php } ?> </div> </body> </html>
The following PHP pages each contain one or more bugs. The bugs could be syntax errors or incorrect logic. Look at each page, find the bug(s), and correct the errors.
T_VARIABLE
and $end
.
If you don't understand an error, try Googling for the error message.
print
for simple variables and print_r
or var_dump
for arrays and objects.
Modify the following HTML to print the first 20 Fibonacci numbers in an ordered list using PHP. Recall that in the Fibonacci sequence, each number is the sum of the two previous numbers, with the first and second numbers being 0 and 1.
<!DOCTYPE html> <html> <head> <title>Fibonacci Sequence</title> </head> <body> <h1>The first twenty Fibonacci numbers:</h1> <!-- (your code here!) --> </body> </html>
... <h1>The first twenty Fibonacci numbers:</h1> <?php $first = 0; $second = 1; for ($i = 0; $i < 20; $i++) { ?> <li><?= $first ?></li> <?php $temp = $second; $second += $first; $first = $temp; } ?>