473,395 Members | 2,468 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

How to retrieve a loggedin user from MySQL database

4
Dear all,

Below here I show you a redirected page from a login.php where shows the results os the login session.
This page will be once again redirected to an edit_user.php page.

The question is how do I retrieve this loggedin user_id from the database.

I have already tried GET_uid and many other forms of request without success.

I would be GREATFUL if any one could help me by that ! THANKS A LOT!


Expand|Select|Wrap|Line Numbers
  1. if (isset($_SESSION['first_name']) && ($_SESSION['last_name' ]) && ($_SESSION['email']) && ($_SESSION['user_id']) && ($_SESSION['registration_date']) )  { 
  2. ?><td><?php  
  3.    echo "<br /><br /><fieldset><p>Welcome, {$_SESSION['first_name']} {$_SESSION['last_name']}!</p>              
  4.    <p>E-mail address: {$_SESSION['email']}</p>
  5.    <p>Registration date: {$_SESSION['registration_date']}</p>
  6.    <p>Your ad...(s)</p> 
  7.    <p>User_id: {$_SESSION['user_id']}</p>";
  8.  echo "</fieldset  >";
  9.  
  10. }
  11.  
  12. if (isset($_GET['uid'])) {
  13. $uid = (int) $_GET['uid'];
  14. if ($uid > 0) {
  15.  $query = "SELECT user_id AS $uid FROM users WHERE user_id = $_SESSION[user_id]" ;      
  16.     $result = @mysql_query ($query);
  17.  
  18. echo '<table> 
  19.       <tr>
  20.        <td align="left"><a href="edit_user.php?view= ' . $SESSION['user_id'] . '">Edit</a></td>
  21.        <td align="left"><a href="delete_user.php?view= ' .  $SESSION['user_id'] . '">Delete</a></td>
  22.      </tr>
  23.     '
  24. ; '</table>' ; 
  25.  
  26.  mysql_close();
  27.   }
  28.  

THANK YOU VERY MUCH ! Naira
Apr 26 '10 #1
7 2251
Atli
5,058 Expert 4TB
Hey.

Is the session variable not working?
The "$SESSION['user_id']" element that is used several time in that code, I mean.
Apr 26 '10 #2
phpuser123
108 100+
Try to echo ur select statement,check if the sql is ok ....
Most probably da problem is somewhere on the sql mostly in line 15..
What does it give u?
Apr 26 '10 #3
Naira
4
@Atli
Hi Atli,

The $_SESSION is working to loggin the user e show the user his name, email, etc, but not to identify him as a retrieved user_id on the page. Nothing else shows up besides the profile of the user.

Many thanks.

Naira
Apr 26 '10 #4
Naira
4
@phpuser123
hi phpuser123,

Thanks for your help.
The sql is running without problems. I have other exercices and everything is doing properly.
I will try yr hint. Meanwhile I found an strong example online from an anonymous and I will try that too tomorrow.

Many thanks
Naira
Apr 26 '10 #5
rythmic
29
The problem is the AS statment in the sql query.

AS is used to create an alias of a table name or column name. Say you had a table called very_extremly_long_col_name it is much more convenient to reference this as velt

so you would write

Expand|Select|Wrap|Line Numbers
  1. SELECT very_extremly_long_col_name AS c1 FROM some_table WHERE c1=3
  2.  
  3. // Then the result would be delivered like this in your php code
  4. $result['c1'];
  5.  
  6.  
  7. // instead of  if not using AS
  8. SELECT very_extremly_long_col_name  FROM some_table WHERE very_extremly_long_col_name=3
  9.  
  10. // imagine getting data from several long named tbls and column and you'll see its a beneficial feature
  11.  
  12.  
So what you need to do is get rid of the AS statement in the sql.
May 4 '10 #6
rythmic
29
@Naira
Also if you didn't notice or if it is a simple typo you have used $SESSION in your delete and edit links instead of $_SESSION which you had correctly used in your sql statement.
May 4 '10 #7
Naira
4
@rythmic
Hello Rythmic,

Sorry for the delay, I was on vacation.
Thank you very much for your suggestion, but the solution was simply this one below:

Expand|Select|Wrap|Line Numbers
  1.  
  2. if (isset($_SESSION['user_id']) AND
  3. (substr($_SERVER['PHP_SELF'], -10)
  4. != 'logout.php')) {
  5.  
  6. echo '<br /><table> 
  7.       <tr>
  8.        <td align="left"><a href="edit_user.php">Edit</a></td>
  9.        <td align="left"><a href="delete_user.php">Delete</a></td>
  10.      </tr>
  11.     ';
  12. echo "</table>"; 
  13.  
  14. } ]
Nothing more than that.

Thanks any way!
Have a nice weekend.

Naira
May 8 '10 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Bob Kaku | last post by:
I'm trying to retrieve a text value from a MySQL database, put it into an updateable form, allow edits, and send back the edited text back into the MySQL database. I've been able to successfully...
7
by: theonlydrayk | last post by:
the script that show image is : <?php include('dbinfo.inc.php'); mysql_connect($localhost,$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query =...
4
by: Robert Kattke | last post by:
Subject: Can you retrieve/restore a MySQL user Password ? I'm working on my own, local WXP, MySQL, version: 3.23.38-nt and I have the "root" password, and normally use the root account. I have...
16
by: Daniel Tonks | last post by:
First, please excuse the fact that I'm a complete MySQL newbie. My site used forum software that I wrote myself (in Perl) which, up until now, has used flat files. This worked fine, however...
5
by: Shimon Sim | last post by:
I am working with LogIn control and need to set some property for profile after user is authenticated. I thought that LoggedIn event is the right place but system tells me that the property can't...
2
by: Jav | last post by:
I need to get at the ProviderUserKey of the logged in user. I would have thought that I could do something like: Dim u As MembershipUser = Membership.GetUser Dim ProvKey as Guid =...
6
by: Daz | last post by:
Hi everyone. Firstly, I apologise if this i not what you would call a PHP problem. I get quite confused as to what lives in which realm, so if this shouldn't be posted here, please suggest where...
5
by: damezumari | last post by:
When a user logs in to my site http://iwantyourquestion.com I set $_SESSION to true if his username and password are OK. When he calls a page I check if $_SESSION is true. If it not I ask him to...
7
by: Vio | last post by:
Hello everyone, i currently a beginner in php. I want to ask about Win2003 Active Directory users. Is it possible to retrieve Win2003 AD (just username & password) with php. I'm currenty...
2
by: santhanalakshmi | last post by:
Hi, Please help me out..... I have created an user in the Mysql database with the password. user : san password : san ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.