Last name | First name | Addresses | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Ajersch | Alex | desc: 0 st | dsfsd: 3423 sad | dsfsd: 3423 sad | des: 123 22 | des: 123 22 | Home: 123 March Road | des: 123 22 | test: test test | test: test test | test: test test | test: 213123 123123 | test: 213123 123123 | yil: | test: 5067 mongolia | test2: 5067 Queen | t: 45 0405 | test2: 5067 Queen | No: 2 Mine | No: 2 Mine |
Anderson | Masey | Escape: 22 Jumpstreet | test: 42 Test St | test: 42 Test St | Thisisatest: 3424 Westcarleton | dsa: 12 fswe | d: d d | d: d d | ||||||||||||
Ashby | Ethan | Cottage: 24601 Newbie_St | homed: 124 phphp | mongolia: 737-1111 f'(x)=7x | ASD: ASD SD | |||||||||||||||
Banner | Bruce | Work: 1 Cave_Park | home: 239057 brick | |||||||||||||||||
Beeblebrox | Zaphod | Cottage: 12 mellow_st | Work: 31 Street St. | lkjhgkjghkj: 42 hitchhiker's way | fgbsfg: wgwr dgfh | fdg: vcxbs dfsadf | ||||||||||||||
Crosbie | Sammy | Hot: 1568 Old Brooke Road | Hot: 1568 Old Brooke Road | No: 2 Mine | ||||||||||||||||
Delos | Lucas | Home: 206 Hitchhikers_Way | HOME: 7-0 united | HOME: 7-0 united | HOME: 7-0 united | |||||||||||||||
Dent | Arthur | ThisDescript: 61345 Testing3432 | Home: 42 Hitchhiker Rd. | STADIUM: 4-1 CAMP NOU | here: w w | here: w w | Cottage: 1 Giorgina St | diznov: 89u43896 lkknesf | ||||||||||||
Gyetko | Dante | Home: 1337 Foobar_Rd | Dumg: Mine Stat | |||||||||||||||||
Hamiltons | Helen | cottage: 2589 | t: t t | |||||||||||||||||
Hawk | Tony | Home: 234 Amanda St | home: 21 skate board | mongolia: e e | ||||||||||||||||
Hickmans | John | Cottage: 12 Test | Cottage: 12 Test | |||||||||||||||||
Holmes | Azaz | Home: 11 Fifth_Ave | Hello: 342 Hello 45st | Hello: 342 Hello 45st | ||||||||||||||||
Moore | Amelia | |||||||||||||||||||
Moore | Isaac | BIG HOUSE: 321 tree ave. | ||||||||||||||||||
Picket | Davis | School: 3088 Dunrobin Rd. | Home: 23 Oakville Drive | |||||||||||||||||
Pinky | Jack | Home: 2 TURTLE_STREET | Cottagee: 42 turt_st | home: 70 butt | adjklsa: 2324 ASjdllk | Paris France: 72312 PSG | Testing123: 4234 asdasd | home: 16 Lismer Crescent | ||||||||||||
Scott | Michael | Cottage: 1 TEst-St | Home: 1234 Dove | |||||||||||||||||
Smith | Ela | Home: 113 Artist_Rd | Cottage: 113 Artist_Rd | skdhsajkhdjksa: sadlmsanm,d asd,mn | ||||||||||||||||
Trumpet | Joshua | Work: 123 Worker_St | Work: 123 Worker_St | WOAH: 928 Kingsview Court | WOAH: 928 Kingsview Court | Work: 123 Worker_St | ||||||||||||||
Willowbee | Putnum | wad: e435 awdga |
<?php
require("database.php");
if(isset($_POST['desc'])){
// print_r($_POST);
// Array
// (
// [cust_id] => 33
// [desc] => Test Addr
// [num] => 42
// [street] => Hitchhiker's way
// [city] => Southampton
// [prov] => ON
// [postal] => H0H0H0
// )
$q = $pdo->prepare("INSERT INTO addresses (addr_cust,addr_desc,addr_number,addr_street,addr_city,addr_prov,addr_postal)
values(:cust,:desc,:num,:street,:city,:prov,:postal)");
$q->bindParam("cust",$_POST['cust_id']);
$q->bindParam("desc",$_POST['desc']);
$q->bindParam("num",$_POST['num']);
$q->bindParam("street",$_POST['street']);
$q->bindParam("city",$_POST['city']);
$q->bindParam("prov",$_POST['prov']);
$q->bindParam("postal",$_POST['postal']);
$q->execute();
echo "Address Added";
}
?>
<!doctype HTML>
<html>
<head>
<style>
table,tr,th,td {
border:1px solid black;
border-collapse:collapse;
}
th,td {
padding: 5px;
}
</style>
</head>
<body>
<?php
$query = $pdo->prepare("SELECT * FROM customers ORDER BY cust_lname,cust_fname");
$query->execute();
$custs = $query->fetchAll(PDO::FETCH_ASSOC);
function getAddrs($custID) {
global $pdo;
$query=$pdo->prepare("SELECT * FROM addresses WHERE addr_cust = :id");
$query->bindParam(":id",$custID);
$query->execute();
$addrs = $query->fetchAll(PDO::FETCH_ASSOC);
return $addrs;
}
?>
<form action="" method="POST">
Customer: <select name='cust_id'>
<?php
foreach($custs as $c) {
echo "<option value='".$c['cust_id']."'>".$c['cust_lname'].", ".$c['cust_fname']."</option>\n";
}
?>
</select></br>
Description: <input type="text" name='desc'></br>
Number: <input type="text" name='num'></br>
Street: <input type="text" name='street'></br>
City: <input type="text" name='city'></br>
Province: <select name='prov'>
<?php
foreach(['AB'=>"Alberta",'BC'=>"British Columbia",'MB'=>"Manitoba",'NB'=>"New Brunswick",'NL'=>"Newfoundland",'NS'=>"Nova Scotia",'NT'=>"NW Territories",'NU'=>"Nunavut",'ON'=>"Ontario",'PE'=>"Prince Edward Island",'QC'=>"Quebec",'SK'=>"Saskatchewan",'YK'=>"Yukon"] as $code=>$prov) {
echo "<option value='$code'>$prov</option>\n";
}
?>
</select></br>
Postal Code: <input type="text" name='postal'></br>
</select>
<br>
<input type="submit" value="ADD ADDRESS">
</form>
<br><br>
<hr>
<table>
<tr><th>Last name</th><th>First name</th><th>Addresses</th></tr>
<?php
foreach ($custs as $c) {
echo "<tr><td>".$c['cust_lname']."</td><td>".$c['cust_fname']."</td>";
foreach(getAddrs($c['cust_id']) as $a) {
// print_r($a);
// [addr_id] => 1
// [addr_cust] => 1
// [addr_desc] => Addr1
// [addr_number] => 3088
// [addr_street] => Dunrobin Rd
// [addr_city] => Dunrobin
// [addr_prov] => ON
// [addr_postal] => K0A1T0
echo "<td><b>".$a['addr_desc']."</b>: ".$a['addr_number']." ".$a['addr_street']."</td>";
}
echo "</tr>\n";
}
?>
</table>
<?php //WILL DISPLAY CODE OF THIS FILE ON THE WEBPAGE//
######################################################################
echo "<br/><br/><hr><hr>";
echo "<h2 style='text-align:center'>END OF OUTPUT</h2>\n";
echo "<hr><hr>";
echo "<h2><br>Source Code of ".basename((string)__FILE__) . "</h2><hr>";
show_source(__FILE__);
#######################################################################
?>
</body>
</html>