PSB™ Status Update PHP Code for Multiple PSB™ Hosts
This PHP code updates the MySQL table containing the Personal Status Board (PSB™) statuses and comments for PSB™s, and, like other server-side scripts (PHP, CGI, ASP), can support many PSB™ users simultaneously. The code first grabs the ID, status, comment, and table name that was posted to it by the main PSB™ page, psb.php. It uses this data to do the updating of statuses and comments. The table name will contain the user name of the administrator. Users and administrators never see the file below—only the PSB™ host sees it, so he will have to replace the "yourusername", "yourpassword" and "yourdatabase" with legitimate names that will enable the MySQL connection to be made and the database to be chosen. Only one database will be used to host PSB™s, and each administrator's data will be entered into the host's "members" table (that contains the users password, and the administrator password and user name, email address, date of joining, and IP of administrator). Each administrator gets 2 other tables as well that are for his group only. The first contains his group's statuses and comments which any group member may change, and the second contains the current meanings of the 100 status codes—which only the administrator may change if his group wants it.
Note that the script submits itself back to psb.php as soon as the table is edited and a couple of field values get posted back to psb.php. The flag set to "1" means "returning from updating the PSB™" and the table name gets sent because even though the psb.php script just sent this value to this update script, the only way it will continue to have the correct table name is if we post it back with POST, send it as a cookie, send it with GET, or use session variables. By posting it back and forth, once a user signs in, his user name will not be subsequently forgotten, since it's now part of the table name. Note the need for JSON in json_encode($table) to convert the table name received in PHP to JavaScript so it could be stuck in the form's hidden field value for posting. There's no other convenient way to do this conversion, although there is a cheap and dirty way to pull off this string conversion.
<html>
<head>
</head>
<body>
<?php
$ID=$_POST['ID'];
$status=$_POST['status'];
$comment=$_POST['comment'];
$table=$_POST['table'];
// Make a MySQL Connection
mysql_connect("localhost", "yourusername", "yourpassword") or die(mysql_error());
mysql_select_db("yourdatabase") or die(mysql_error());
// Update record where id = $ID in their table in db yourdatabase
$query="UPDATE $table SET Status='$status', Comment='$comment' WHERE ID='$ID'";
mysql_query($query) or die ("Trouble updating database");
echo "Record Updated";
mysql_close();
?>
<form name="MyForm" method="POST" action="psb.php">
<input type="hidden" name="flag" value="1">
<input type="hidden" name="table" value=" ">
</form>
<script language="javascript">
var tbl = <?php echo json_encode($table); ?>;
document.MyForm.table.value=tbl;
document.MyForm.submit();
</script>
</body>
</html>