Forum Moderators: coopster

Message Too Old, No Replies

Send to specific page

tried all day and still nothing...

         

burdstuff

12:34 am on Jan 10, 2009 (gmt 0)

10+ Year Member



I posted an earlier article and got no help. I'm really having a hard time with this. I probably read hundreds of pages after doing goolge search after google search. I think I'm just not typing the correct search strings. But here's my issue and I think I am getting close I just need that little nudge.

I have a login screen that takes the user to a member page.

This is where my problem lies.

I have a bunch of users who are in tennis devisions. Mens Singles, Mens Doubles etc etc. In my database they are listed as

divsioncode:
ms
md
etc
etc

What I want to do is, once they land on there account page, I have a link for them to click. All it does is take them to a page that only shows other players within their own divisioncode.

Please if anyone can help it would be greatly appreciated.

bkeep

12:47 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



I am not exactly sure how your database is setup but something like this should work with some modifications.

have a link to [somesite.com...]


function getUserRecords($division)
{
$sql = "SELECT * FROM users WHERE division = '" . $division . "'";
$res = mysql_query($sql);

$c=0;
while ($a_row = mysql_fetch_array($res)) {
$records[$c]["id"] = $a_row["id"];
$records[$c]["email"] = $a_row["email"];
$records[$c]["division"] = $a_row["division"];
$records[$c]["user"] = $a_row["user"];
$records[$c]["first_name"] = $a_row["first_name"];
$records[$c]["last_name"] = $a_row["last_name"];
$records[$c]["phone"] = $a_row["phone"];
$records[$c]["alt_phone"] = $a_row["alt_phone"];
$records[$c]["fax"] = $a_row["fax"];
$records[$c]["image"] = $a_row["image"];
$records[$c]["address"] = $a_row["address"];
$records[$c]["city"] = $a_row["city"];
$records[$c]["state"] = $a_row["state"];
$records[$c]["zip"] = $a_row["zip"];
$records[$c]["reg_date"] = $a_row["reg_date"];
$records[$c]["image"] = $a_row["image"];
$c++;
}
if (!empty($records))
return $records;
}

then do something like this on your page


if (isset($_GET["division"])) {
$division = mysql_real_escape_string((get_magic_quotes_gpc())? stripslashes($_GET["division"]): $_GET["division"]);
$records = getUserRecords($division);
}

then display the results however you want


print_r($records);

burdstuff

3:48 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



Thanks for the reply!

Heres the basics how my database is setup

Databasename = somename
Table = users
------------------------------------------
/ID / Name / Phone /Pass / Divisioncode
/1 / a / # /P / MS40
/2 / b / # /p / MD25
/3 / c / # /P / MS40

-------------------------------------------

How would I go about implementing that?

my pages are like this

login-

accountpage-
---on the page is a link to look at other players in division, which as of right now only shows EVERY person in the database for EVERY divisioncode

burdstuff

7:55 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



Okay I have it working but I have a problem

members.php?divisioncode=

How do I make it so it adds the specific variable according to what divisioncode the user who logged in, is in?

If i got and type
?divisioncode=ms45 it brings up the correct members
if i change it to ms50 it also works.

The problem is, how do I get that to automatically happen per user?
So I get members.php?divisioncode="divisioncode"

bkeep

8:20 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



how ever you are pulling out that users username and whatnot to authenticate them for that page.

So if you use $row['id'] for their id then just add another section to pull out that $row['Divisioncode']

so something like this
print "<a href=\"members.php?divisioncode=$row[Divisioncode]\">Other members in your division</a>";

burdstuff

8:42 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



link:
$MM_redirectLoginSuccess = "somesite.php?divisioncode=$colname_results[Divisioncode]";

code:
$colname_results = (get_magic_quotes_gpc()) ? $_GET['divisioncode'] : addslashes($_GET['divisioncode']);

isn't working.

bkeep

10:14 pm on Jan 10, 2009 (gmt 0)

10+ Year Member



Can you display the username onto the members page? if so what code do you use to do that?

burdstuff

1:55 am on Jan 11, 2009 (gmt 0)

10+ Year Member



yup

login:
$_SESSION['user']= $email;

------------------------------------------------------------
Member Page:
<?php if (isset($_SESSION['user'])) { ?>
<p>Logged as <?php echo $_SESSION['user']; ?>

burdstuff

2:43 am on Jan 12, 2009 (gmt 0)

10+ Year Member



Thanks for all your help so far but I'm lost on how to get it to display now ;/ I think I'm putting the wrong strings in the wrong pages. I doubled up the array in the login and in the myaccount pages just incase I can get it to work in the account page later.

login
-------------------------------------------
<?php
include 'dbc.php';

$email = mysql_real_escape_string($_POST['email']);

if ($_POST['Submit']=='Login')
{
$pass = ($_POST['password']);
$sql = "SELECT id,email FROM users WHERE
email = '$email' AND
password = '$pass'";

$result = mysql_query($sql) or die (mysql_error());
$num = mysql_num_rows($result);

if ( $num != 0 ) {

// A matching row was found - the user is authenticated.
session_start();
list($user_id,$email) = mysql_fetch_row($result);
// this sets variables in the session
$_SESSION['user']= $email;

function getUserRecords($divisioncode)
{
$sql = "SELECT divisioncode FROM users WHERE divisioncode = '" . $divisioncode . "'";
$res = mysql_query($sql);

$c=0;
while ($a_row = mysql_fetch_array($res)) {
$records[$c]["id"] = $a_row["id"];
$records[$c]["email"] = $a_row["email"];
$records[$c]["divisioncode"] = $a_row["divisioncode"];
$records[$c]["user"] = $a_row["user"];
$records[$c]["firstname"] = $a_row["firstname"];
$records[$c]["lastname"] = $a_row["lastname"];
$records[$c]["home"] = $a_row["home"];
$c++;
}
if (!empty($records))
return $records;
}

if (isset($_GET['ret']) && !empty($_GET['ret']))
{
header("Location: $_GET[ret]");
} else
{
header("Location: myaccount.php?divisioncode=$a_row[divisioncode]");
}
//echo "Logged in...";
exit();
}

header("Location: login.php?msg=Invalid Login");
//echo "Error:";
exit();
}

?>

<link href="styles.css" rel="stylesheet" type="text/css">

<?php if (isset($_GET['msg'])) { echo "<div class=\"msg\"> $_GET[msg] </div>"; } ?>

<p>&nbsp;</p><table width="40%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td bgcolor="#d5e8f9" class="mnuheader" >
<div align="center"><font size="5"><strong>Login
Members</strong></font></div></td>
</tr>
<tr>
<td bgcolor="#e5ecf9" class="mnubody"><form name="form1" method="post" action="">
<p>&nbsp;</p>
<p align="center">Your Email
<input name="email" type="text" id="email">
</p>
<p align="center"> Password:
<input name="password" type="password" id="password">
</p>
<p align="center">
<input type="submit" name="Submit" value="Login">
</p>
<p align="center"><a href="forgot.php">Forgot Password?</a></p>
</form></td>
</tr>
</table>
----------------------------------------------------------------------

myaccount.php
----------------------------------------------------------------------
<?php
session_start();
if (!isset($_SESSION['user']))
{
die ("Access Denied");
}
{
include("dbc.php");
}
function getUserRecords($divisioncode)
{
$sql = "SELECT divisioncode FROM users WHERE divisioncode = '" . $divisioncode . "'";
$res = mysql_query($sql);

$c=0;
while ($a_row = mysql_fetch_array($res)) {
$records[$c]["id"] = $a_row["id"];
$records[$c]["email"] = $a_row["email"];
$records[$c]["divisioncode"] = $a_row["divisioncode"];
$records[$c]["user"] = $a_row["user"];
$records[$c]["firstname"] = $a_row["firstname"];
$records[$c]["lastname"] = $a_row["lastname"];
$records[$c]["home"] = $a_row["home"];
$c++;
}
if (!empty($records))
return $records;
}

?>
<h2>My Account </h2>

<?php print "<a href=\"list_records.php?divisioncode=$row[Divisioncode]\">Other members in your division</a>"; ?>
<?php if (isset($_SESSION['user'])) { ?>

<p>Logged as <?php echo $_SESSION['user']; ?> ¦ <a href="settings.php">Settings</a>
¦ <a href="logout.php">Logout</a>
¦ <a href="list_records.php">Something</a> </p>
<?php } ?>

----------------------------------------------------------------------
list-records.php
----------------------------------------------------------------------
<?php

include("dbc.php");

// Retrieve data from database
if (isset($_GET["divisioncode"])) {
$division = mysql_real_escape_string((get_magic_quotes_gpc())? stripslashes($_GET["divisioncode"]): $_GET["divisioncode"]);
$records = getUserRecords($divisioncode);
}

// Start looping rows in mysql database.

print_r($records); {
?>
<table width="60%" border="1" cellspacing="0" cellpadding="3">
<tr>
<td width="10%"><? echo $a_row['skilllevel']; ?></td>
<td width="20%"><? echo $records['fullname']; ?></td>
<td width="10%"><? echo $a_row['home']; ?></td>
<td width="10%"><? echo $data['cell']; ?></td>
<td width="10%"><? echo $data['work']; ?></td>
<td width="20%"><? echo $data['city']; ?></td>
<td width="10%"><? echo $data['divisioncode']; ?></td>
</tr>
</table>

<?
// close while loop
}

// close connection
mysql_close();
?>
----------------------------------------------------------------------

I just really need a second set of eyes to see what I'm doing wrong at this point. Anyway

Login works, myaccount works but list_records fails. I'm probably not getting the array to display correctly.

If I could it would be optimal to get the records display in the account page but I don't even know how to insert the code correctly for it. Oh and I'm still failing to have what the members divisioncode is equal to in the URL. I've walked away and come back from this after taking a break for a day and have hit the wall on it.