Forum Moderators: coopster
This is what I have to do.
I'm working on a tennis league site, and I already have the database built. All the players have registered and created accounts with all necessary information. I read this post to help with what I'm trying to accomplish.
[webmasterworld.com...]
What I'm trying to do is get the users in one division, say 4 to see only other players in division 4 after they login. 5 sees 5, 6-6 and so on. Nothing fancy just a table with the other players contact info.
The information displayed is like so......
Name phone# city memberID division
someone 5555555 a city 7777777 4
someone2 5555556 somecity 7777777 4
I'm using scripts I found around the internet to help but I can't get my page to display. my login and members pages all work it's just getting to see the other players in the same division that I'm banging my head over.
Here's the code:
login.php
----------------------------------------------------------------------
<?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;
if (isset($_GET['ret']) && !empty($_GET['ret']))
{
header("Location: $_GET[ret]");
} else
{
header("Location: myaccount.php");
}
//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> </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> </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>
----------------------------------------------------------------------
What would be ideal is once they get to their myaccount page is to just throw up the division roster right there.
But for now I'm trying this....
myaccount.php
----------------------------------------------------------------------
<?php
session_start();
if (!isset($_SESSION['user']))
{
die ("Access Denied");
}
?>
<h2>My Account </h2>
<?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="something.php">Something</a> </p>
<?php } ?>
----------------------------------------------------------------------
something.php this is the test I was doing using the code I found in the linked post, with modifications to match my database column names.
----------------------------------------------------------------------
<?php
session_start();
if (!isset($_SESSION['user']))
{
die ("Access Denied");
}
?>
<?
$query = “SELECT * FROM membernumer WHERE user_id=’{$_SESSION[‘membernumber’]}’”;
$result = mysql_query ($query) or (… -> error message);
if ($result){
//-> Load results
while ($row = mysql_fetch_assoc($result)){
$firstName = $row[‘firstname’];
$lastName = $row[‘lastname’];
$email = $row[‘email’];
etc…
etc…
}
?>
//->You’ll set up a single template page to hold the structure for the information like….
<html>
<body>
<p>First Name: <? echo $firstName;?></p>
<p>Last Name: <? echo $lastName;?></p>
<p>Email: <? echo $email;?></p>
} else {
//-> DB query failed – do something
}
----------------------------------------------------------------------
I played around with this for a bit but I doubt it's the right script for what I'm trying to accomplish. All I get are blank pages.
I broke up <html> info above </html> code and made a separate page and still nothing. I know my db is working because I ran this simple script to actually see the data I have in it.
----------------------------------------------------------------------
<?php
include("config.php");
// Retrieve data from database
$tbl_name="users";
$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
// Start looping rows in mysql database.
while($rows=mysql_fetch_array($result)){
?>
<table width="60%" border="1" cellspacing="0" cellpadding="3">
<tr>
<td width="10%"><? echo $rows['skilllevel']; ?></td>
<td width="20%"><? echo $rows['fullname']; ?></td>
<td width="10%"><? echo $rows['home']; ?></td>
<td width="10%"><? echo $rows['cell']; ?></td>
<td width="10%"><? echo $rows['work']; ?></td>
<td width="20%"><? echo $rows['city']; ?></td>
<td width="10%"><? echo $rows['divisioncode']; ?></td>
</tr>
</table>
<?
// close while loop
}
// close connection
mysql_close();
?>
----------------------------------------------------------------------
And I know it's not secure right now. I had md5 tags that I removed because the data base I had didn't have md5 encrypted passwords so I just took out the tags until I do get them encrypted.
So yup. I know it probably looks like a hot mess. But if anyone can tell me what the hell I'm doing wrong it would be wicked awesome. Thanks!
This is probably due to fatal errors. Have you checked your error log lately?
The key to getting this to work is here:
$query = “SELECT * FROM membernumer WHERE user_id=’{$_SESSION[‘membernumber’]}’”;
And it looks like you have a good handle on how to accomplish it. It's just the displaying of the results that you are getting stuck with, it seems. Here is a thread that might give you some help: [webmasterworld.com...]
good luck