Previous Thread
Next Thread
Print Thread
Rate Thread
Joined: Mar 2000
Posts: 528
Junior Member
Junior Member
Offline
Joined: Mar 2000
Posts: 528
I am adding two tables to my database, and adding two php pages. My intention is to add an area where we can designate "ranks" and "chapter affiliation" to our members, and toggle whether someone is a "member" or not.

I took the showugroups.php and made it showmemgroups.php - same format (check boxes) and I also added two text boxes to fill in.

I took the dochangeugroups.php and made it dochangememgroups.php - to feed the data from the above page back into the database.

I added mem_table (fields: Mem_UserName, Mem_Number, Mem_Title, Mem_Joined, Mem_Groups) and I also added mem_groups (Grp_ID, Grp_Name)

I have the following code I hacked in showmemgroups.php:

// Require the library
require ("../main.inc.php");

// -----------------
// Get the user info
$Username = $w3t_myname;
$Password = $w3t_mypass;
$userob = new user;
$user = $userob -> authenticate("$Username","$Password","U_Username, U_Password,U_Groups");
$html = new html;

// -----------------------------
// Make sure they should be here
if ( ($user[U_Status] != 'Moderator') && ($user[U_Status] != 'Administrator')){
$html -> not_right ("You must be logged in, and be a valid administrator or moderator to access this.",$Cat);
}

// -----------------------------------
// Find out what groups they belong to
$Username_q = addslashes($User);
$query = "
SELECT Mem_Groups, Mem_Number, Mem_Title, Mem_Joined
FROM mem_table
WHERE Mem_Username = '$Username_q'
";
$sth = $dbh -> do_query($query);
list($Groups,$Number,$Title,$Joined) = $dbh -> fetch_array($sth);
$dbh -> finish_sth($sth);

// ---------------------------------------------------------
// Ok, we found the profile, now lets put it all onto a page
$html -> send_header("Change user's groups ($User)",$Cat,0,$user[Mem_Username],0,0,$user);
$html -> table_header("Change user's groups ($User)");
$html -> open_table();
echo "
<TR><TD CLASS="lighttable">
<FORM METHOD=POST ACTION="$config[phpurl]/admin/dochangessbmembers.php">
<INPUT TYPE=HIDDEN NAME=Cat value="$Cat">
<INPUT TYPE=HIDDEN NAME=User value="$User">
Place a checkmark in either ACTIVE or NON-ACTIVE, and next to the games the member is currently playing.
</p><p>

Member Rank<br>
<input type = text name = Title value = "$Title" class="formboxes">
<br><br>
Date Joined<br>
<input type = text name = Joined value = "$Joined" class="formboxes">
<br><br>
";

// --------------------------------
// Now let's list all of the groups
$query = "
SELECT Grp_Name, Grp_Id
FROM mem_groups
";
$sth = $dbh -> do_query($query);

// --------------------------------------------------------------------
// This gets somewhat confusing. Basically we are echoing out a table
// with 3 columns. When we are done listing the groups then we need
// to fill out the rest of the table with nbsp;
echo "<TABLE BORDER=0 WIDTH="$theme[tablewidth]" ALIGN="$theme[tablealign]">";
$row =0;
while ( list($Name,$Id) = $dbh -> fetch_array($sth)) {
if ($row == 0) { echo "<TR>"; }
$row++;
echo "<TD width=50% class="lighttable">";
$checky = "-$Id\-";
$checked = "";
if (ereg($checky,$Groups)) {
$checked = "CHECKED";
}

echo "<INPUT TYPE=CHECKBOX NAME="$Id" $checked VALUE="on" class="formboxes"> ";
echo "$Name";
echo "</TD>";
if ($row == 2) {
echo "</TR>";
$row = 0;
}
}
$dbh -> finish_sth($sth);

if ($row > 0) {
for ( $i=0; $i<(3-$row); $i++) {
echo "<TD width=33% class="lighttable"> </TD>";
}
echo "</TR>";
}
echo "
</TABLE>
<input type=submit name=option value="Submit" class="buttons">
</FORM>
";
$html -> close_table();

// ----------------
// send the footer
$html -> send_footer();
?>


The dochangememgroups.php looks like this:


// Require the library
require ("../main.inc.php");
// -----------------
// Get the user info
$Username = $w3t_myname;
$Password = $w3t_mypass;
$userob = new user;
$user = $userob -> authenticate("$Username","$Password","U_Username, U_Password");
$html = new html;

// -----------------------------
// Make sure they should be here

if ($user[U_Status] != 'Administrator'){
$html -> not_right ("You must be logged in, and be a valid administrator to access this.",$Cat);
}

// -----------------------------------
// Find out what groups they belong to
$Username_q = addslashes($User);
$query = "
SELECT Mem_Groups, Mem_Number, Mem_Title, Mem_Joined
FROM mem_table
WHERE Mem_Username = '$Username_q'
";
$sth = $dbh -> do_query($query);
list($Groups,$Number,$Title,$Joined) = $dbh -> fetch_array($sth);
$dbh -> finish_sth($sth);

// -------------------------------
// Now let's get all of the groups
$query = "
SELECT Grp_Name, Grp_Id
FROM mem_groups
";
$sth = $dbh -> do_query($query);

// --------------------------------------------------------------------
// Now we chug through the groups. If it was checked, we add them to
// the group. If it was unchecked we remove them from it.

$total = 0;
while ( list($Name,$Id) = $dbh -> fetch_array($sth)) {
$total++;
if ($HTTP_POST_VARS[$Id]) {
if (!ereg("-$Id-",$Groups)) {
$Groups .= "$Id-";
}
}
else {
$Groups = preg_replace("/-$Id-/","-",$Groups);
}
}
$dbh -> finish_sth($sth);

// -----------------------
// Format the query words

$Groups_q = addslashes($Groups);
$Number_q = addslashes($Number);
$Title_q = addslashes($Title);
$Joined_q = addslashes($Joined);

// --------------------------
// Update the User's profile

$query = "
UPDATE mem_table
SET Mem_Groups = '$Groups_q'
Mem_Number = '$Number_q',
Mem_Title = '$Title_q',
Mem_Joined = '$Joined_q',
WHERE Mem_Username = '$Username_q'
";

$dbh -> do_query($query);

// ---------------------
// Send the confirmation

$html -> send_header("This users groups have been changed.",$Cat,"<META HTTP-EQUIV="Refresh" content="5;url=$config[phpurl]/admin/login.php?Cat=$Cat">",$user[U_Username],0,0,$user);
$html -> table_header("This users groups have been changed.");
echo "<TABLE BORDER=0 WIDTH="$theme[tablewidth]" ALIGN="$theme[tablealign]"><TR><TD class="cleartable"><span class="onbody">";
echo "This users groups have been changed. You will now be returned to the main administration page.";
echo "</span></TD></TR></TABLE>";

// ----------------
// send the footer

$html -> send_footer();?>


And finally (thanks for reading this far down...) I get the following error when hitting the UPDATE button:

SQL ERROR: Unable to do_query: UPDATE mem_table SET Mem_Groups = '' Mem_Number = '', Mem_Title = '', Mem_Joined = '', WHERE Mem_Username = 'Medar'
You have an error in your SQL syntax near 'Mem_Number = '', Mem_Title = '', Mem_Joined = '', WHERE ' at line 4: 1064

Any ideas? MANY THANKS.

Sponsored Links

Link Copied to Clipboard
Donate Today!
Donate via PayPal

Donate to UBBDev today to help aid in Operational, Server and Script Maintenance, and Development costs.

Please also see our parent organization VNC Web Services if you're in the need of a new UBB.threads Install or Upgrade, Site/Server Migrations, or Security and Coding Services.
Recommended Hosts
We have personally worked with and recommend the following Web Hosts:
Stable Host
bluehost
InterServer
Visit us on Facebook
Member Spotlight
isaac
isaac
California
Posts: 1,157
Joined: July 2001
Forum Statistics
Forums63
Topics37,573
Posts293,925
Members13,849
Most Online5,166
Sep 15th, 2019
Today's Statistics
Currently Online
Topics Created
Posts Made
Users Online
Birthdays
Top Posters
AllenAyres 21,079
JoshPet 10,369
LK 7,394
Lord Dexter 6,708
Gizmo 5,833
Greg Hard 4,625
Top Posters(30 Days)
Top Likes Received
isaac 82
Gizmo 20
Brett 7
WebGuy 2
Morgan 2
Top Likes Received (30 Days)
None yet
The UBB.Developers Network (UBB.Dev/Threads.Dev) is ©2000-2024 VNC Web Services

 
Powered by UBB.threads™ PHP Forum Software 8.0.0
(Preview build 20221218)