Old 04-12-2005   #1 (permalink)
Registered User
 
ViciOuS's Avatar
 
Join Date: Apr 2005
Posts: 82

Simple Member script help?

Hello once again. I am trying to make a simple member system for my clan site. If you would please take a moment to view my site (http://www.clanadvanced.com) and see how simple indeed the member system is.

Now, the whole script works just fine and dandy except for one part, please take a look at this page to see what i mean. I need this to be like the members list on the site if you know what i mean, lol.

Here are my 2 pages.

AddMember.php
Code:
<?php
include('session_vars.php');
// Check to see if they are logged in..
if ($enpw != $pw){
header("Location: ../ad_login.php");}

else if(!$action){
?>

<BODY background="../images/image_22.gif" OnLoad="self.focus();document.addmember.name.focus()">

<div align="center">
<br><a href="#" target="iframe" title="Remove Member(s)">Remove Member(s)</a>
<br><br>

 <FORM ACTION="?action=submit" method="POST" name="addmember">
  <TABLE width="80%" valign="center">

    <tr bgcolor="#CCCCCC">
     <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
&nbsp;Member Name: </td>
     <td><INPUT type="text" name="member" tabindex="1" size="30"></td>
    </tr>

<br><br>

    <tr bgcolor="#EEEEEE">
     <td><font face="Verdana, Arial, Helvetica, sans-serif" size="2">
&nbsp;Rank: </td>
     <td>
        <select name="rank">
        <option value="Member">Member</option>
        <option value="Senior Member">Senior Member</option>
        <option value="Council">Council</option>
        </select>
     </td>
    </tr>

  </TABLE>
  <TABLE width="80%" valign="center">
    <tr bgcolor="#CCCCCC">
     <td><center>
        <INPUT type="submit" tabindex="5" name="submit" value="Add Member">
       </center></td>
    </tr>
  </TABLE>
 </FORM>
<br><br>
[<a href="Loggedin.php" target="iframe"> Back to Admin CP </a>]
<br>
<a href="../members.php" target="iframe">Members List</a>
</div>

<?php

 }else if($action == "submit") {

include('mysql_connect.php');

 if(empty($member)) exit("Please Select a Rank and provide a Member to Add");

// add slashes
$member = addslashes($member);

// add data into database
mysql_query("INSERT INTO members (member,rank) VALUES ('$member','$rank')") or die(mysql_error());


echo "Successfully Added $member as $rank<br><br><a href=\"Loggedin.php\" target=\"iframe\">Return to the Admin Panel</a>";
}
?>
members.php
Code:
<html>
<head>
<title>Members List</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style>
<!--
a{text-decoration:none}
//-->
</style>
<style>
a:link{color:orange; text-decoration:underline; }
a:hover{color:orange; text-decoration:underline; }
</style>
</head>

<BODY BGCOLOR=#332815 background="images/image_22.gif" link="#000000" vlink="#F00000" bgproperties="fixed" LEFTMARGIN=2 TOPMARGIN=0 MARGINWIDTH=0 MARGINHEIGHT=0>
<?php
include('admincp/mysql_connect.php');

$query = mysql_query('SELECT * FROM members ORDER BY id DESC');

while($row = mysql_fetch_object($query)) {

$rank = $row->rank;
$name = $row->member;

 if($rank == "Member") {
$member_list = $name;}

 else if($rank == "Senior Member") {
$senior_list = $name;}

 else if($rank == "Council") {
$council_list = $name;}
?>

<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr> 
    <td><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2">Members List</font></b></td>

  </tr>
  <tr>
    <td bgcolor="#F5F5F5">
<table align="center" width="100%" border="0">
  <tr>
    <td align="center"><font face="Verdana, Arial, Helvetica, sans-serif" size="2"><br>

<u><b>Leader and Founder</b></u><br>Dahnkuana[aD]

     <br><br>

<u><b>Council</b></u><br>
<?php echo $council_list; ?><br>

     <br><br>

<u><b>SeniorMembers</b></u><br>
<?php echo $senior_list; ?><br>

     <br><br>

<u><b>Members</b></u><br>
<?php echo $member_list; ?><br>

     <br><br>

</font>
    </td>
  </tr>
</table>
    </td>
  </tr>
</table>

</body>
</html>

<?php
}
?>
Can someone please tell me what i'm doing wrong?
ViciOuS is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 04-12-2005   #2 (permalink)
code anyone?
 
scrowler's Avatar
 
Join Date: Feb 2004
Location: New Zealand
Posts: 590

Send a message via MSN to scrowler Send a message via Skype™ to scrowler
the second page doesn't load :O
__________________
BioRUST Tutorials - the birthplace
scrowler is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 04-12-2005   #3 (permalink)
Registered User
 
ViciOuS's Avatar
 
Join Date: Apr 2005
Posts: 82

Yeah, currently theres something wrong with my server. I'm going to have to talk to my host and see what he can do about it. My whole site isn't working right and I can't get into my cpanel :-\

Anyways, I will bump this topic once my server is fixed unless you can figure out whats wrong with my code without seeing that page.
ViciOuS is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 04-13-2005   #4 (permalink)
Registered User
 
ViciOuS's Avatar
 
Join Date: Apr 2005
Posts: 82

Okay, my site is working and you can view that page now.

Thanks for your patience in advance.
ViciOuS is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 04-13-2005   #5 (permalink)
code anyone?
 
scrowler's Avatar
 
Join Date: Feb 2004
Location: New Zealand
Posts: 590

Send a message via MSN to scrowler Send a message via Skype™ to scrowler
Code:
<?php

mysql_connect("localhost", "user", "pass");
mysql_select_db("db_name");

$main = "SELECT * FROM members WHERE rank = ";

# edit the ends of the following to mimic the MySQL stored data that determines ranking.
# edit the keys of the array to mimic the desired output ranking.
$sql["Leader"] = $main . "Leader";
$sql["Council"] = $main . "Council";
$sql["Senior Members"] = $main . "SeniorMembers";
$sql["Members"] = $main . "Members";

echo '<div style="text-align: center">';

foreach($sql as $key => $current){

echo "<p><u>$key</u></p><p>";

$do = mysql_query($current);
while($row = mysql_fetch_assoc($do)){
echo $row['name'] . '<br />';
}

echo '</p><p>&nbsp;</p>';

}

?>
try that
__________________
BioRUST Tutorials - the birthplace
scrowler is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 04-13-2005   #6 (permalink)
Registered User
 
ViciOuS's Avatar
 
Join Date: Apr 2005
Posts: 82

Okay, here is my code for members.php:

Code:
<?php
include('admincp/mysql_connect.php');

$main = "SELECT * FROM members WHERE rank = ";

# edit the ends of the following to mimic the MySQL stored data that determines
# the ranking.
# edit the keys of the array to mimic the desired output ranking.
$sql["Council"] = $main . "Council";
$sql["Senior Members"] = $main . "Senior Member";
$sql["Members"] = $main . "Member";

echo '<div style="text-align: center">';

foreach($sql as $key => $current){

echo "<p><u>$key</u></p><p>";

$do = mysql_query($current);
while($row = mysql_fetch_assoc($do)){
echo $row['member'] . '<br />';
}

echo '</p><p>&nbsp;</p>';

}

?>
Even though i'm not exactly sure how $current works in foreach($sql as $key => $current){

I still changed everything else that needed to be changed to fit my MySQL db and etc.

Check the page to see the error.
ViciOuS is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 04-13-2005   #7 (permalink)
code anyone?
 
scrowler's Avatar
 
Join Date: Feb 2004
Location: New Zealand
Posts: 590

Send a message via MSN to scrowler Send a message via Skype™ to scrowler
sorry, i missed a bit, change this:
Code:
# after the last }
echo '</div>';
also, foreach is a constructor built for arrays, $sql is the array representor, $key is the dynamic variable that represents the name of the key in each iteration of the array, and $current will contain the current value (SQL code) as it iterates through the array.

this appears to be an SQL error, try modifying the following:
Code:
$do = mysql_query($current);
# change to
$do = mysql_query($current) or die(mysql_error());
and report if there is an error and if so, what is it?

Last edited by scrowler; 04-13-2005 at 09:26 AM.
scrowler is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 04-13-2005   #8 (permalink)
Registered User
 
ViciOuS's Avatar
 
Join Date: Apr 2005
Posts: 82

Now i get: Unknown column 'Council' in 'where clause'

I don't see how thats an unknown column though. Btw, thanks for explaining that foreach() constructor, it helps a lot.
ViciOuS is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 04-13-2005   #9 (permalink)
Local Biorust Beast
 
Order's Avatar
 
Join Date: Oct 2003
Location: San Diego, CA, USA
Posts: 2,253

Send a message via AIM to Order Send a message via MSN to Order Send a message via Yahoo to Order
try 'council' as opposed to 'Council'.. PHP can be touchy with formatting, caps are evil :P
__________________
Order is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 04-13-2005   #10 (permalink)
Registered User
 
ViciOuS's Avatar
 
Join Date: Apr 2005
Posts: 82

nah, now it just says: Unknown column 'council' in 'where clause'

lol..
ViciOuS is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 04-14-2005   #11 (permalink)
Local Biorust Beast
 
Order's Avatar
 
Join Date: Oct 2003
Location: San Diego, CA, USA
Posts: 2,253

Send a message via AIM to Order Send a message via MSN to Order Send a message via Yahoo to Order
I see the problem, $main is a sql return value, not a string. You will need to use one of the mysql functions to turn it into usable values.
__________________
Order is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 04-14-2005   #12 (permalink)
Registered User
 
ViciOuS's Avatar
 
Join Date: Apr 2005
Posts: 82

Is there somewhere I can learn about these mysql functions that turn sql return values into string? or can you show me?

Either way, It would be of much help.
ViciOuS is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 04-14-2005   #13 (permalink)
Local Biorust Beast
 
Order's Avatar
 
Join Date: Oct 2003
Location: San Diego, CA, USA
Posts: 2,253

Send a message via AIM to Order Send a message via MSN to Order Send a message via Yahoo to Order
Something like this may help:

PHP Code:
$main "SELECT * FROM members ORDER BY id DESC";

if(
$ret mysql_query($main))
{
  while(
$row mysql_fetch_array($ret))
  {
    echo 
'<pre>';
    
print_r($row);
    echo 
'</pre>';
  }
} else {
  die(
'MySQL Error: ' mysql_error());

Take a look at the results, it will show you what the $row arrays look like for your members, to adapt it to your site, remove the code within the while loop. Boom, instant member list.

Also, I am not one for doing all the hard work, I will only get you where you need to get, my help requires your intelligence, otherwise there is no learning.
__________________
Order is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 04-14-2005   #14 (permalink)
Registered User
 
ViciOuS's Avatar
 
Join Date: Apr 2005
Posts: 82

Well, first off, I want it to display the right names under the correct rank. Not just a list of all the members. Although I did try and use your code in with mine and here is what I came up with:

Code:
<?php
include('admincp/mysql_connect.php');

$main = "SELECT * FROM members WHERE rank=";

$sql["Council"] = $main . "Council";
$sql["Senior Members"] = $main . "Senior Members";
$sql["Members"] = $main . "Members";

echo '<div style="text-align: center">';

foreach($sql as $key => $current){

echo "<p><u>$key</u></p><p>";


 if($ret = mysql_query($main))
 {
   while($row = mysql_fetch_array($ret))
   {
    echo $row['member'] . '<br />';;
   }
 } else {
   die('MySQL Error: ' . mysql_error());
 } 

 echo '</p><p>&nbsp;</p>';

}
?>
I get an error under the council rank saying:
"You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1"

I tryed taking out (WHERE rank=") but it just displays all the members under all the ranks.
ViciOuS is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Old 04-14-2005   #15 (permalink)
code anyone?
 
scrowler's Avatar
 
Join Date: Feb 2004
Location: New Zealand
Posts: 590

Send a message via MSN to scrowler Send a message via Skype™ to scrowler
Code:
if($ret = mysql_query($main))
# change to
if($ret = mysql_query($current))
__________________
BioRUST Tutorials - the birthplace
scrowler is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT +1. The time now is 06:36 PM.
Content Relevant URLs by vBSEO 3.2.0

Design & Content © BioRUST 2008 :: PRIVACY STATEMENT :: LEGAL INFORMATION :: ADVERTISING MEDIA KIT