Jump to content

Recommended Posts

thankyou for looking at my problem

 

i have code set up so i can deleted users data edit it see it ect... im having trouble showing only the users data that is logged in

i uses the session $id = $_SESSION['user_id']; to get the users id who is logged in... it should be easy but i seem to be having a mind blank out but with the code provided here

 

<?php


include("connect.php");

$query="SELECT * FROM users ";
$result=mysql_query($query);
$num = mysql_num_rows ($result);
mysql_close();


$first_name = mysql_result($result,$i,"first_name");
$events = mysql_result($result,$i,"events");
$about_me = mysql_result($result,$i,"about_me");
$dob = mysql_result($result,$i,"dob");
$id = mysql_result($result,$i,"ID");

echo "<b>First Name:</b> $first_name<br>";
echo "<b>Events:</b> $events<br>";
echo "<b>About me:</b> $about_me<br>";
echo "<b>DOB:</b> $dob<br>";
echo "<a href=\"update.php?id=$id\">Update</a> - <a href=\"delete.php?id=$id\">Delete</a>";
echo "<br><br>";

++$i; } } else { echo "The database is empty"; }?>

 

to just show the users logged on currently data?

Link to comment
https://forums.phpfreaks.com/topic/87587-bringing-up-users-data/
Share on other sites

I do it the same way as well, works great.

 

But you are not doing a WHERE clause in your Query

 

$query="SELECT * FROM users WHERE userid='$id'";

 

 

It should work if you do it the way that revraz described. Only you need to make sure it's personallized to your data, which looks like you'd need to do:

$id = $_SESSION['user_id'];
$query="SELECT * FROM users WHERE ID='$id'";

 

 

Which is what he said he did in his original post, but I don't think it's setting this $id to the User's Session, I think it's set to his.

 

thankyou for looking at my problem

i uses the session $id = $_SESSION['user_id']; to get the users id who is logged in... it should be easy but i seem to be having a mind blank out but with the code provided here

 

He said it but I didn't see it in any of his code.

 

I don't know who's id he's getting, but if its supposed to get what he says it is, he still needs a loop to get it all. I'm assuming he's logged in as well, and if he is admin, his ID is probably first. There is no loop and it's only going to output one value, the $num variable is not being used. runner, are you getting YOUR information every time or some other problem?

 

I think he's either loading his own ID, or loading all and only calling the first one(which would be his).

$id = $_SESSION['user_id']; gets the current logged in datas id numner so e.g

 

runnerjp has id 1

zhadus has id 2

revras has id id

 

i want to look at revas data so i would use $id = $_SESSION['user_id']; to find revras id from his logged in status and its 3.... so i will get all data under 3

 

so how i add it into my data

And what would you use for zhadus or runnerjp's status?  You can't use $id = $_SESSION['user_id']; for everyone's, you have to pull the info from some unique place.

 

$id = $_SESSION['user_id']; gets the current logged in datas id numner so e.g

 

runnerjp has id 1

zhadus has id 2

revras has id id

 

i want to look at revas data so i would use $id = $_SESSION['user_id']; to find revras id from his logged in status and its 3.... so i will get all data under 3

 

so how i add it into my data

i use

session_start();

require_once '../settings.php';

$query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1"; [code] to gather a users username from i id which is fround by using this function

[code]function checkLogin ( $levels )
{
	session_start ();
	global $db;
	$kt = split ( ' ', $levels );

	if ( ! $_SESSION['logged_in'] ) {

		$access = FALSE;

		if ( isset ( $_COOKIE['cookie_id'] ) ) {//if we have a cookie

			$query =  'SELECT * FROM ' . DBPREFIX . 'users WHERE ID = ' . $db->qstr ( $_COOKIE['cookie_id'] );

			if ( $db->RecordCount ( $query ) == 1 ) {//only one user can match that query
				$row = $db->getRow ( $query );

				//let's see if we pass the validation, no monkey business
				if ( $_COOKIE['authenticate'] == md5 ( getIP () . $row->Password . $_SERVER['USER_AGENT'] ) ) {
					//we set the sessions so we don't repeat this step over and over again
					$_SESSION['user_id'] = $row->ID;				
					$_SESSION['logged_in'] = TRUE;

					//now we check the level access, we might not have the permission
					if ( in_array ( get_level_access ( $_SESSION['user_id'] ), $kt ) ) {
						//we do?! horray!
						$access = TRUE;
					}
				}
			}
		}
	}
	else {			
		$access = FALSE;

		if ( in_array ( get_level_access ( $_SESSION['user_id'] ), $kt ) ) {
			$access = TRUE;
		}
	}

	if ( $access == FALSE ) {
		header('Location: http://runningprofiles.com/members/index.php');
	}		
}

hope that helps a lil more[/code][/code]

Depends what you are trying to do.  I don't understand why you would want to delete a users data that is logged in.

 

Build a useradmin page, list all the users, put a delete button next to each one and then use that.  I posted yesterday or day before on how to do that in another thread.

 

Now if you want the User to be able to edit their own profile, that's a different story.  But I can't tell what you are trying to do.

 

ok well how would you do it :P

oh sorry im very bad at explainin things lol ok the delte thing ignor lol thats just for me i used it as a learnin curve so like u say i can delete users

 

 

i want users to be able to update their own profile yes :)  at the moment i have this

 

<?php

include("connect.php");
$query = "SELECT * FROM users WHERE Username = '$username' LIMIT 1";
$result=mysql_query($query);
$num = mysql_num_rows ($result);
mysql_close();

if ($num > 0 ) {
$i=0;
while ($i < $num) {
$first_name = mysql_result($result,$i,"first_name");
$events = mysql_result($result,$i,"events");
$about_me = mysql_result($result,$i,"about_me");
$dob = mysql_result($result,$i,"dob");
$id = mysql_result($result,$i,"ID");

echo "<b>First Name:</b> $first_name<br>";
echo "<b>Events:</b> $events<br>";
echo "<b>About me:</b> $about_me<br>";
echo "<b>DOB:</b> $dob<br>";
echo "<a href=\"update.php?id=$id\">Update</a> - <a href=\"delete.php?id=$id\">Delete</a>";
echo "<br><br>";

++$i; } } else { echo "The database is empty"; }?>

where it displays all the users in the data and their info... all i want to do is have just the user to see their OWN profile and edit their OWN profile :D

This is what I do, it should give you the basic idea.  I also have some error checking after it, but this should get you started

 

<?php
session_start();

if (!isset ($_SESSION['uid'])) {
header ("Location: index.php");
}
else {
$id = $_SESSION['uid'];
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>My Profile</title>
<link href="indexstyle.css" rel="stylesheet" type="text/css" />
</head>
<body>
<?php
include("navbar.php");
include('config/conf.php');
include('functions/functions.php');

$connection = mysql_connect($host,$user,$pass)or die ('Unable to connect');
mysql_select_db($db) or die ('Unable to select DB');

if (!$_POST['submit']) {

$query = "SELECT * FROM users WHERE uid = '$id'";
$result = mysql_query ($query) or die ("Error in query: $query. " . mysql_error());

if (mysql_num_rows($result) > 0) {
	$row = mysql_fetch_object($result);
	?>


	<div id="profile">
	<h2>My Profile</h2>
	<table>

	<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
	<input type="hidden" name="id" value="<?php echo $id; ?>">
	Username: <?php echo $row->uname; ?><br />
	<a href = "changepw.php">Change Password</a><br />
	First Name: <input type="text" name="ufname" size="10" value = "<?php echo $row->ufname ?>"><br />
	Last Name: <input type="text" name="ulname" size="10" value = "<?php echo $row->ulname ?>"><br />
	Phone: <input type="text" name="phone" size="12" value = "<?php echo $row->uphn ?>"><br /> 
	Email Address: <input type="text" name="email" size="30" value = "<?php echo $row->uemail ?>"><br />
	<?php $_SESSION['uemail']=$row->uemail; ?>
	Timezone Offset from Eastern: <input type="text" name="offset" size="5" value="<?php echo $row->offset ?>"><br />
	Registration Date: <?php echo date('m/d/Y',$row->regdate); ?><br /><br />
	<center><input type="submit" value="Update" name="submit"></center>
	</form>	
	</table>
	</div>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.