PHP link

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

mademokid
Forum Commoner
Posts: 25
Joined: Tue Jul 10, 2007 11:10 am

PHP link

Post by mademokid »

I have two problems.

1. I want to put a variable into a link. Eg. http://www.forum.example.com/index.php?showuser=[b]$id[/b]
2. I know this needs to be in the database forum, but it's related to my 1st issue. I want to query my mySQL database to get the id of the user who is logged in. EG. I am logged in as example. I want example to be shown the link http://www.forum.example.com/index.php?showuser=1 because he has an id of 1

Any suggestions?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Do you understand the use of echo()?
mademokid
Forum Commoner
Posts: 25
Joined: Tue Jul 10, 2007 11:10 am

Post by mademokid »

Erm....
Not really

I'm pretty novice and use tutorials and such, but I would like to increase my knowlege.

If you could give me an example of how I could use echo to do this I would be greatful.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Code: Select all

<?php
$var = 'in Canada...';

echo 'I slept near a bear ' . $var;
?>
mademokid
Forum Commoner
Posts: 25
Joined: Tue Jul 10, 2007 11:10 am

Post by mademokid »

Okay, so that solves the fist problem. What about the second?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

How do you currently know which user is logged in?
mademokid
Forum Commoner
Posts: 25
Joined: Tue Jul 10, 2007 11:10 am

Post by mademokid »

I only know if I am logged in atm
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Sorry, I should have asked how the code knows anyone is logged in.
mademokid
Forum Commoner
Posts: 25
Joined: Tue Jul 10, 2007 11:10 am

Post by mademokid »

User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Sorry, I can't stand about.com's pages and I really do not feel like sifting through them at the moment.

So what you are saying is you snagged code from the web and are not sure how to implement it?
mademokid
Forum Commoner
Posts: 25
Joined: Tue Jul 10, 2007 11:10 am

Post by mademokid »

I can get the code to work fine. I want to be able to use a variable in a link. The variable comes from a mySQL database and is on the same row as the username of the member. It is the member id and I want to use it to show a members profile page by the member clicking on it. I want only the member to be able to access it.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

mademokid wrote:The variable comes from a mySQL database and is on the same row as the username of the member.
So where in the code does the app know to use this id? What I am getting at is the only way to offer this link for the person that is logged in is to know who is logged in. Typically that is done with sessions. If you have session data, then you can easily add a session var with the logged in users ID to be used as a regular var later in the code.
mademokid
Forum Commoner
Posts: 25
Joined: Tue Jul 10, 2007 11:10 am

Post by mademokid »

I am using a IPB member table

It has id,name,......

I want a code that will associate the logged in user with the correct id from the table and then use the id as a variable in a link
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Sorry, I think you and I are going around in circles. Somewhere in your code that you are trying to extend there needs to be something, codewise, that will tell the app that someone is logged in. Otherwise, there is no chance of doing anything with any logged in user data because the app will not know that someone is logged in.

The part of the code that keeps track of someone being logged in is the part of the code you want to leverage to get the id of who is logged, at which point you can use their information for all sorts of other goodies.
mademokid
Forum Commoner
Posts: 25
Joined: Tue Jul 10, 2007 11:10 am

Post by mademokid »

Would it help if I posted the code for my login and members areas?
Post Reply