<script language="php">
 #
 # this include file has the passwords and 
 # database names defined in it  
 #
 require('../sql_passwords.php');
 echo "<h1>SQL insert &amp; delete statements</h1>\n";
 #
 # connect to SQL
 #
 $link = mysql_connect($z_hardcoded_sqlurl, 
                       $z_hardcoded_database, 
                       $z_hardcoded_password )
                       or die('Could not connect: ' . mysql_error());
 #
 # select the database I want to use
 #
 mysql_select_db($z_hardcoded_database) or die('Could not select database');








 echo "<h2>Does any data exists? Do a SELECT</h2>";
 echo "<table border=0>\n";
 echo "<tr><td>\n";
 echo "</td><td>\n";
 $query = 'SELECT name,count FROM `counters` where name=\'happydogmeat\'';
 $result = mysql_query($query) or die('Query failed: ' . mysql_error());
 $query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
 $query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
 $query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
 $numberofrows=0;
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 echo "<tr><td colspan=2>$query</td></tr>";
 while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    $numberofrows++;
    echo "<tr>\n";
    foreach ($line as $col_value) {
        if ($col_value == '' ) {
           $col_value='&nbsp;';
        }
        echo "<td>$col_value</td>\n";
    }
    echo "</tr>\n";
 }
 if ($numberofrows == 0 ) {
    echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;No Data for that key</td></tr>";
 }
 echo "</table>\n";
 #
 # i am not sure but i think this frees the
 # stuff associated with the current select so
 # you can do a new select
 #
 // Free resultset
 mysql_free_result($result);





 echo "<h2>Try to INSERT some data</h2>";
 #
 # display the selected stuff
 #
 echo "<table border=2>\n";
 #
 # if no data exists the first insert will work and the others will fail
 # if any data exists all the inserts will fail
 #
 for ($i=1;$i<4;$i++) {
    $query = 'INSERT into `counters` set name=\'happydogmeat\', count=\''.$i.'\'';
    #
    # this is a second way of doing it
    #
    #      INSERT INTO `counters` ( `name` , `count` ) 
    #           VALUES ('dogmeat', '0');
    #
    echo "<tr><td colspan=2>$query</td></tr>";
    $result = mysql_query($query);
    if ($result) {
       echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;Insert worked</td></tr>";
    }
    else {



       echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;<SPAN style=\"color: red\">Insert failed</span></td></tr>";
    }
 }
 echo "</table>\n";










echo "<h2>SELECT the inserted data</h2>";
$query = 'SELECT name, count FROM `counters` where name=\'happydogmeat\'';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
$query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
$query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
$numberofrows=0;
#
# display the selected stuff
#
echo "<table border=2>\n";
echo "<tr><td colspan=2>$query</td></tr>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "<tr>\n";
   $numberofrows++;
   foreach ($line as $col_value) {
       if ($col_value == '' ) {
          $col_value='&nbsp;';
       }
       echo "<td>$col_value</td>\n";
   }
   echo "</tr>\n";
   if ($numberofrows == 0 ) {
      echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;No Data for that key</td></tr>";
   }
}
echo "</table>\n";









echo "<h2>DELETE all the data that matches this key</h2>";
echo "<table border=1>\n";
$query = 'DELETE from `counters` where name=\'happydogmeat\'';
echo "<tr><td colspan=2>$query</td></tr>";
$result = mysql_query($query);
if ($result) {
 echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;Delete worked</td></tr>";
}
else {
 echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;Delete failed</td></tr>";
}
echo "</table>\n";














echo "<h2>Do a SELECT to show no data exists</h2>";
$query = 'SELECT name, count FROM `counters` where name=\'happydogmeat\'';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
$query=preg_replace ( '/from/i', '<br>&nbsp;from', $query);
$query=preg_replace ( '/where /i', '<br>&nbsp;where ', $query);
$query=preg_replace ( '/order /i', '<br>&nbsp;order ', $query);
$numberofrows=0;
#
# display the selected stuff
#
echo "<table border=2>\n";
echo "<tr><td colspan=2>$query</td></tr>";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
   echo "<tr>\n";
   $numberofrows++;
   foreach ($line as $col_value) {
       if ($col_value == '' ) {
          $col_value='&nbsp;';
       }
       echo "<td>$col_value</td>\n";
   }
   echo "</tr>\n";

}
if ($numberofrows == 0 ) {
   echo "<tr><td colspan=2>&nbsp;&nbsp;&nbsp;&nbsp;No Data for that key</td></tr>";
}


echo "</table>\n";
#
# i am not sure but i think this frees the
# stuff associated with the current select so
# you can do a new select
#
// Free resultset
mysql_free_result($result);














#
# close the SQL connection
#
// Closing connection
mysql_close($link);
</script>