R
E
S
O
U
R
C
E
S
       Home      Products & Services      Contact Us      Links


WebHatchers will design & develop your site for you.
_______________________

Website Menu Heaven: menus, buttons, etc.
_______________________

Send us your questions.
_______________________

site search by freefind
_______________________

HOME
SEO, Google, Privacy
   and Anonymity
Browser Insanity
JavaScript
Popups and Tooltips
Free Website Search
HTML Form Creator
Animation
Buttons and Menus
Counters
Captchas
Image Uploading
CSS and HTML
PHP
AJAX
XPATH
Website Poll
IM and Texting
Databases—MySQL
   or Not MySQL
Personal Status Boards
Content Management
   Systems
Article Content
   Management Systems
Website Directory
   CMS Systems
Photo Gallery CMS
Forum CMS
Blog CMS
Customer Records
   Management CMS
Address Book CMS
Private Messaging CMS
Chat Room CMS
JavaScript Charts
   and Graphs




Free Personal Status Boards (PSB™)

Free Standard Free PSB

Free PSB Pro Version

Free Social PSB

Free Social PSB Plus (with Email)

Free Business PSB

Free Business PSB Plus (with Email)

PSB demo

Social PSB demo

Business PSB demo

So what's all this PSB stuff about?

Chart comparing business status boards

PSB hosting diagram

PSB Licence Agreement



Copyright © 2002 -
MCS Investments, Inc. sitemap

PSBs, social networking, social evolution, microcommunities, personal status boards
PSBs, social networking, business personal status boards
website design, ecommerce solutions
website menus, buttons, image rotators
Ez-Architect, home design software
the magic carpet and the cement wall, children's adventure book
the squirrel valley railroad, model railroad videos, model train dvds
the deep rock railroad, model railroad videos, model train dvds

Add Group Member

The add-group-member.php script lets administrators add a new user's first name and the rest of the record to the administrator's PSB™ table. Any name of 1 to 12 characters containing only letters, numbers and underline is okay. Editing group members or deleting group members are done in other scripts.

In adding a group member name and the rest of the record in the administrator's PSB™ table, the configure.php is included to establish server and database connections. Next, we get the username and new fname variables POSTed to our PHP script, with the username being POSTed from the page that sent us here and the other variables getting POSTed from this member adding page to itself. Note that if the Administrator is not logged in and therefore his username (stored in $U) is unset, he is sent to the login page. If the $A variable is not set, he has not yet entered data into the form.

Once the $A variable is set with the new first name, the PHP script adds the specified first name and the rest of the record to the Administrator's PSB™ table where first names, IDs, statuses and comments are stored. To do this, the table gets queried with "SELECT max(ID) FROM $B", which finds the maximum ID number in the ID column of the table. This ID number gets incremented before using it as the ID of the new member. This is critical because the new ID has to be greater than the rest of the ID numbers or the PSB™ will not function right.

Let's look at how MySQL databases work. The PRIMARY key, when we push it into a PHP array after pulling it from the database with MySQL commands in PHP, will ALWAYS come out of the database table as a sorted array, but the other fields will be unsorted arrays—in the same order as they were originally entered. If we use the MySQL command ORDER BY, we can get displayed HTML tables in which rows/records DISPLAY in any desired order. But this does NOT mean that these sorted display values can be pushed into PHP arrays in sorted form. When we try, we always get the PRIMARY field array sorted in ascending order, but the other fields will be unsorted arrays—in the same order as they were originally entered. There is no way to get ALL the fields' arrays to be in parallel, as long as we include the PRIMARY key in the mix. If we leave it out, the fields used will all be unsorted arrays, representing records in parallel, with element 3 in each array, for example, representing the various fields in one distinct record/row. This works. Once we found this out, we gave up plans to have the ID field be PRIMARY (therefore presorted). Instead, we assigned a different unused field, N, as PRIMARY, and never thought about it again, never displaying it or using it. It was set to be an auto-incrementing field so we needn't stick values into an INSERT—just use empty quotes (MySQL knows what to do with these). With the ID field now parallel to the other fields when we pushed the values into arrays, there were no more problems, but before we took the PRIMARY attribute from ID, there were loads of problems. The reason that most people use ID as PRIMARY is that if all you plan to do is display the records in HTML tables, all works smoothly—PRIMARY ID fields are a good choice for this use. But our plans included putting the values in PHP arrays which we then converted to JavaScript arrays using JSON, for use in the browser. For example, in the PSB™ we change the generic "Member Status" to a specific member's name once the "Change Status" button is clicked, and we needed the JavaScript arrays to accomplish this. The reason we even had a PRIMARY field is that MySQL requires it in order to keep things straight, internally.

In the process of deleting members (which sometimes happens), holes in the ID number sequences arise which could hold a new member later, and sure enough, when we add a new member, they often fill the gap. However we don't mean there's a gap between records 3 and 5 that gets plugged with record 4. No, the new record that gets plugged into the gap in the table is one higher than the highest numbered record (because we programmed it that way). If the highest record number was 12, then 13 gets plugged in the gap between 3 and 5. (Of course, you can always use the phpMyAdmin utility and access the MySQL database and put records where you want with whatever ID numbers you want. But this is surely doing things the hard way, and you cannot expect users of apps you build to do this.) This "mixing records in the MySQL table" phenomenon doesn't hurt anything as long as we are not utilizing the PRIMARY field for anything. The way we make sure that all IDs are distinct and unique is to force a newly added group member's ID to be one higher than the highest existing number, which is easily done with MySQL's "SELECT max(ID) FROM tablename" function. Add 1 to these results and we have our new member's ID. One cannot predict how and when MySQL will decide to plug a hole. As one MySQL expert puts it: "there is no such thing as a beginning, middle, or end with MySQL tables." So trying to "append" a record to the "end," even if it has the highest ID number, is a fool's errand. Once a deletion causes a gap, new records will go into the gaps and there is nothing that can be done about it. If you have records that will never ever suffer a deletion, you just MAY be able to keep the latest, highest numbered record at the end of the MySQL table. But why create apps that rely on this when it's not necessary? When we grab the "last" record in a table, regardless of whether we're refering to the actual position in the table or the record (not necessarily last) with the highest ID number, it will always create PHP and JavaScript arrays with element number 6 in each array representing one single MySQL row/record. But if we counted on the highest ID being last, and gaps have EVER occured for ANY reason, we'd get arrays with mixed records. In sum, then, it's good practice to avoid counting on record positions in tables, and it's likewise good practice to use no PRIMARY fields in your record data (but instead use an unused column as an auto-incrementing PRIMARY) when you need to use arrays to store your MySQL table records for use in a browser app.

Note that we check through the Firstname data in the table to make sure the group member added is not a duplicate. If it is, we don't add the name, but give a warning message instead.

If the table gets appended successfully, you get a message to that effect. Success is detected by a special MySQL function, mysql_affected_rows(). Once the appending is done, there's a button to let the administrator return to the Administrators Page. Note that JSON is used to pass the user name from PHP to JavaScript and then it gets POSTed back to PHP by the form in this script as well as to the Administrator page. This keeps the user logged in so he need not login constantly as he uses various editing scripts.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=windows-1252">
<TITLE>Add Group Member</TITLE>
<meta name="description" content="Add Group Member">
<meta name="keywords" content="Add Group Member,php,javascript, dhtml, DHTML">
<style type="text/css">
BODY {margin-left:0; margin-right:0; margin-top:0;text-align:left}
p, li {font:13px Verdana; color:black;text-align:left}
h1 {font:bold 28px Verdana; color:black;text-align:center}
h2 {font:bold 24px Verdana;text-align:center}
h3 {font:bold 15px Verdana;}
</style>
</head><body>

<div style='position:absolute;top:450px;left:370px;border:1px solid black;background-color:#eee;'>

<?php

include_once"configure.php";

$U=$_POST['username'];
$A=$_POST['fname'];

if (!isset($U)) {
echo '<script language="javascript">alert("Please login.");
window.location="login.php"; </script>';
}

$B=$U."_psb";

$result = mysql_query("SELECT * FROM $B") or die(mysql_error());

echo "<table border='1' width='162'>";
echo "<tr><th>ID</th><th>First Name</th></tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr><td>";
echo $row['ID'];
echo "</td><td>";
echo $row['Firstname'];
echo "</td></tr>";
}
echo "</table>";

if (isset($A)) {

$dupe=0;

$myArray=array();

$res = mysql_query("SELECT Firstname FROM $B") or die(mysql_error());
while ($row = mysql_fetch_row($res)) {
array_push ($myArray, $row[0]);
}

$num=mysql_num_rows($result);

for($i=0;$i<$num;$i++){
if($A==$myArray[$i]){unset($A);$dupe=1;}
}
if($dupe==1){$dupe=0;echo '<script language="javascript">alert("This name already exists.");</script>';}else{

$result = mysql_query("SELECT max(ID) FROM $B") or die(mysql_error());
$row = mysql_fetch_row($result);
$number=$row[0]+1;

mysql_query("INSERT INTO $B (N, Firstname, ID, Status, Comment)
VALUES('','$A','$number','99','')");
$rc = mysql_affected_rows();
if ($rc>0){unset($A);
echo '<script language="javascript">alert("The change was successfully accomplished.");</script>';}
else{echo '<script language="javascript">alert("The change was unsuccessful.");</script>';}
}
?>

<div style='position:absolute;top:0px;left:0px;border:1px solid black;background-color:#eee;'>

<?php

$B=$U."_psb";

$result = mysql_query("SELECT * FROM $B") or die(mysql_error());

echo "<table border='1' width='162'>";
echo "<tr><th>ID</th><th>First Name</th></tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr><td>";
echo $row['ID'];
echo "</td><td>";
echo $row['Firstname'];
echo "</td></tr>";
}
echo "</table>";

?>

</div>

<?php
}

mysql_close();
?>
</div>

<h1>Add Group Member</h1>

<div id='pw' style='position:absolute;top:150px;left:370px;width:262px'><table style="background-color:#8aa;border-color:#00f" border='6' cellspacing=0 cellpadding=6><tr><td>
<form id='formpw' name="formpw" method="post" action="add-group-member.php" onsubmit="return validatefname()">
<label for="First Name"><b>First Name:    </b><input type="text" name="fname" size="12" maxlength="12" value=""></label><br><br>
<input type="hidden" name="username" value=" ">
<input type="submit" value="Add Group Member"><br><br>
<input type="reset" value="Reset"></form></td></tr></table>

<br><br>

<form style='margin-left:0px' name="MyForm" method="POST" action="administrator-page.php">
<input type="button" value="Return to Administrator Page" onclick="goback()">
<input type="hidden" name="username" value=" ">
</form>

</div>

<script language="javascript">

function goback(){
var u = <?php echo json_encode($U); ?>;
document.MyForm.username.value=u;
document.MyForm.submit();}

function validatefname(){

var u = <?php echo json_encode($U); ?>;
document.formpw.username.value=u;

var ck_username = /^[A-Za-z0-9_]{1,12}$/;
if (document.formpw.fname.value.search(ck_username)==-1)
{alert("Please only enter letters, numbers and underline for user first names, and enter 1 to 12 characters.");return false}

return true;}

</script>

</body></html>