#!/bin/bash
echo "Content-Type: text/html; charset=utf-8"
echo
echo "<html><head><style>"
echo "table { border-collapse: collapse }"
echo "td, th { border: 1px solid; padding: 4px }"
echo "th { background-color: lightyellow }"
echo "tr:nth-child(even) { background-color: #ccc }"
echo "</style></head>"
echo "<body><h1>Table of Stored Names</h1>"
echo "<form action="http://localhost/~sandiway/get2.cgi" method="GET">"
echo "First: <input type="text" name="first" size=12>"
echo "Last:  <input type="text" name="last" size=12>"
echo "<input type="submit"></form>"
origIFS=$IFS
IFS='=&'
set -- $QUERY_STRING
IFS=$origIFS
# names.txt must exist and
# be write-able for everyone (www)!
echo "$2 $4" >> names.txt
echo "<table><tr><th>First</th><th>Last</th></tr>"
while read -r first last
do
    echo "<tr><td>$first</td><td>$last</td></tr>"
done < names.txt
echo "</table>"
echo "</body></html>"
exit 0

