FreeBSD Programming Primer – Part 8
// Check selected table is valid $s = $sql[0]; // Replace the marker in the SQL statement with the chosen value
$s = str_replace ( ‘---P0---’ , $t , $s ); $result = mysql_select($s);
// HTML form definition echo ‘<div id=”content”>’; echo ‘<div id=”php”>’;
echo ‘<div id=”h1”>1: Select content</div>’;
echo ‘<form action=”amendcontent.php” method=”post”>’; echo ‘<select name=”table”>’; foreach ($tables as $t){ // $tables is an array - split each value out
$valid_table_count = $result[‘COUNT(DISTINCT TABLE_NAME)’];
if($valid_table_count == 1){ // Valid table selected - present form to edit data
build_page_2($t,$sql,$skiplist);
} // Finish form and add footer echo ‘</select>’;
echo ‘<input type=”submit” value=”Select content to
}else{ // Send user to first page build_page_1($tables);
echo ‘</form>’;
edit”>’;
echo ‘</div></div>’;
echo ‘<div id=”licence”>’;
echo ‘<a href=”licence.txt” title=”Copyright and licence
}
details”>Copyright &copy; 2013 Rob
} }elseif(isset($_POST[“update”])){ // Save the input. As we have not validated this, just display for now
build_page_3($_POST); }else{ // Invalid value - return to start build_page_1($tables); } /////////////////////////////////////////////////// /////////////////////////////////////////////////// /////////////////////////////////////////////////// function build_page_1($tables){
www.bsdmag.org
echo ‘<option value=”’.$t.’”>’.$t.’</option>’;
echo ‘</div>’;
Somerville me@merville.co.uk</a>’;
} function build_page_2($t,$sql,$skiplist){ // HTML form echo ‘<div id=”content”>’; echo ‘<div id=”php”>’;
echo ‘<div id=”h1”>2: Edit <?php
echo $t;
?>&nbsp;content</div>’;
echo ‘<form action=”amendcontent.php” method=”post”>’; // Get the schema for that particular table $s = $sql[1];
$s = str_replace ( ‘---P0---’ , $t , $s ); $result = mysql_fetchrows($s);
$divstart = ‘<div class=”inputname”>’;
31