<script language="php">
$debug=0;
require('../sql_passwords.php');
$zname=$_POST['zname'];
$zvalue=$_POST['zvalue'];
$zdelete=$_POST['zdelete'];
$zname=$_REQUEST['zname'];
$zdelete=$_REQUEST['zdelete'];
$zvalue=$_REQUEST['zvalue'];
$errors=0;
$errort="";
$zpassword=$_REQUEST['zpassword'];
$zvalue=0;
#
# 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');
#
# get a copy of the playpen database
# we will merge it with the production database
#
$query = 'SELECT name,count FROM `counters_playpen`';
$result = mysql_query($query) or die('Query failed: ' . mysql_error());
#
# display the selected stuff
#
$numberofrows=0;
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
$i=0;
foreach ($line as $col_value) {
if ($i == 0 ) {
$name[$numberofrows]=$col_value;
$i++;
}
else {
$data[$numberofrows]=$col_value;
$numberofrows++;
$i=0;
}
}
}
#
# 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);
#
# display the data in the counter playpen database
#
if ($debug) {
echo "<table border=1>\n";
for ($i=0;$i<$numberofrows;$i++) {
echo "<tr><td>$name[$i]</td><td>$data[$i]</td></tr>";
}
echo "</table>";
}
#
# delete everything in the playpen database
#
#
$query = 'DELETE from `counters_playpen` ';
$result = mysql_query($query);
#
# check how many rows got deleted
#
#$numberofrows = mysql_num_rows($result);
$numberofrows = mysql_affected_rows();
if ($debug) {
echo "$numberofrows have been deleted<br>";
}
#
# copy the counter database into the playpen counter database
# please note the data to insert is generated from a SELECT
# of another database ie: counters as opposed to
# counters_playpen
#
$query = 'INSERT into `counters_playpen`
(counters_playpen.name, counters_playpen.count)
SELECT counters.name, counters.count FROM `counters` ';
$result = mysql_query($query);
#
# add the orginal data back in
# some will be rejected if they also exist in the production
#
for ($i=0;$i<$numberofrows;$i++) {
$query = 'INSERT into `counters_playpen` (name, count) values
(\''.$name[$i].'\',\''.$data[$i].'\') ';
if ($debug) {
echo "query=$query<br>";
}
$result = mysql_query($query);
if ($result) {
#echo "INSERT WORKED $name[$i] $data[$i] <br>";
}
else {
#echo "Insert failed $name[$i] $data[$i]<br>";
}
}
#
# close the SQL connection
#
// Closing connection
mysql_close($link);
require('sql_i_u_d.php');
exit;
</script>