This topic is locked
[SOLVED]

 How to create a hyperlink using session variables?

11/6/2007 9:02:51 PM
PHPRunner General questions
R
runnerPHP2008 author

After users log in, they have a session variable that is associated with their record in the database.
Here is the question:
How do I dynamically link to pages using these session variables?
For example, here is a sample database:
ID Name

01 John

02 Mary

03 Steve
After users log-in, they are redirected to a welcome.php page that I designed using Dreamweaver. I want to create a link on my welcome.php page that will dynamically link to EDIT.php using the variables of the user that is logged in.
Example:
Lets say that Steve logs in, I want my welcome.php page to have a link to EDIT his record:
<a href="http://www.domain.com/_Project_edit.php?ID=03">;
but the problem is that the link above is not dynamic, so if Mary clicked on the link, her ID is 02, not 03, so it will not work
How do I create a link using variables of users that are logged in?

<a href="http://www.domain.com/_Project_edit.php?ID=[current logged in user]">
thank you

Admin 11/6/2007

Take a look at the list of PHPRunner Session variables:

http://www.xlinesoft.com/phprunner/docs/ph...n_variables.htm
$_SESSION["UserID"] stores logged user name. If you like to use ID field for this purpose you need to write an extra code that pulls ID from login table based on user name.

R
runnerPHP2008 author 11/6/2007

THis is the link that I created based on the information you have given me:
<a href="http://www.domain.com/_Project_edit.php?ID=$_SESSION["UserID"]">;
This still does not work because it redirects to the Log-in page

I also tried putting the "UserID" in single quotes 'UserID', but it did not work.
What is the hyperlink supposed to look like? Do I need to include any files on my custom php page?
thanks

Take a look at the list of PHPRunner Session variables:

http://www.xlinesoft.com/phprunner/docs/ph...n_variables.htm
$_SESSION["UserID"] stores logged user name. If you like to use ID field for this purpose you need to write an extra code that pulls ID from login table based on user name.

J
Jane 11/7/2007

Hi,
you need to pull ID of current user and then use it in your link.

Here is a sample:

global $conn;

$str = "select ID from users where name='".$_SESSION["UserID"]."'";

$rs = db_query($str,$conn);

if ($data = db_fetch_array($rs))

echo "<a href=\"http://www.domain.com/_Project_edit.php?ID=".$data["ID"]."\">Link</a>";;



Also I recommend you to learn PHP and SQL so you can implement this on your own.

R
runnerPHP2008 author 11/18/2007

I am still having problems, but I understand your solution. Below is the code I have saved as a .php file. I am getting an error about the call to function not found "db_query" on line 5:
<?php
global $conn;

$str = "select ID from users where name='".$_SESSION["UserID"]."'";

$rs = db_query($str,$conn);

if ($data = db_fetch_array($rs))

echo "<a href=\"http://www.domain.com/_Project_edit.php?ID=".$data["ID"]."\">Edit Your Ad</a>";
?>
<html>

<head>

<TITLE>Title of website</TITLE>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<link rel="stylesheet" type="text/css" href="CommonStyles.css" />

</head>
<body bgcolor="#bb4411" text="#000000">

<div align="center">

<table width="71%" border="0" cellspacing="0" cellpadding = 10 bgcolor = "#ffffff" id="fullheight">

<tr>

<td style="border-bottom:solid 4px #bb4411">

<div align="center"><img src="https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=23425&image=1&table=forumreplies"; width="491" height="52"></div>

</td>

</tr>
</table>

</td>

</tr>

</table>

</div>

</body>

</html>
How do I integrate this PHP code within my HTML code?

J
Jane 11/19/2007

Hi,
to add PHP code to your template use custom events on the page (Insert PHP code snippet option on the Visual Editor tab).

R
runnerPHP2008 author 11/26/2007

I do not want to add PHP code to a template, I have created a separate .php page. I just need to know what include files to add to this page and how to design it...

Hi,

to add PHP code to your template use custom events on the page (Insert PHP code snippet option on the Visual Editor tab).

J
Jane 11/27/2007

Hi,
you need to include dbcommon.php file:

include("include/dbcommon.php");