Page 1 of 2
PHP link
Posted: Tue Jul 10, 2007 12:10 pm
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?
Posted: Tue Jul 10, 2007 2:08 pm
by feyd
Do you understand the use of
echo()?
Posted: Tue Jul 10, 2007 2:11 pm
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.
Posted: Tue Jul 10, 2007 2:24 pm
by RobertGonzalez
Code: Select all
<?php
$var = 'in Canada...';
echo 'I slept near a bear ' . $var;
?>
Posted: Tue Jul 10, 2007 2:32 pm
by mademokid
Okay, so that solves the fist problem. What about the second?
Posted: Tue Jul 10, 2007 2:34 pm
by RobertGonzalez
How do you currently know which user is logged in?
Posted: Tue Jul 10, 2007 2:35 pm
by mademokid
I only know if I am logged in atm
Posted: Tue Jul 10, 2007 2:37 pm
by RobertGonzalez
Sorry, I should have asked how the code knows anyone is logged in.
Posted: Tue Jul 10, 2007 2:38 pm
by mademokid
Posted: Tue Jul 10, 2007 2:40 pm
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?
Posted: Tue Jul 10, 2007 2:43 pm
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.
Posted: Tue Jul 10, 2007 2:46 pm
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.
Posted: Tue Jul 10, 2007 2:48 pm
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
Posted: Tue Jul 10, 2007 2:52 pm
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.
Posted: Tue Jul 10, 2007 2:53 pm
by mademokid
Would it help if I posted the code for my login and members areas?