Custom link

Hey guys…:slight_smile:
So im trying to create a sidebar for my site and when user logs in he will be able to edit hes profile, to do so he must go to a custom link, but how do I add one of those?
This is what Ive been trying;

<p><a href="member.php?loginid="\.$_SESSION["username"]."\">'.$_SESSION["username"].'</a></p>

The link text works perfectly… But the link does not edit… When I click on it I go to:
http://www.myhomepage.com/folder/member.php?loginid=

Does anyone know how to fix this…?
Thanks :slight_smile:

should be:

<p><a href=“member.php?loginid=<?php echo $_SESSION[“username”]; ?>”&gt;<?php echo $_SESSION[“username”]; ?></a></p>

or

<?php
echo “<p><a href='member.php?loginid=” . $_SESSION[“username”] . “’\>” . $_SESSION[“username”] . “</a></p>”;
?>

Yeah, I kinda tryed thing like that and number of others, but I keep getting an error;

Parse error: syntax error, unexpected T_STRING, expecting ‘)’ in functions/menus.functions.php on line 63

Anyway, heres my full code;

**<?php session_start();

[U]if[/U]($_GET[‘set’] > 0)
{

[U]if[/U]($_SESSION['whattoclose'] == NULL)
{

	$_SESSION['whattoclose'] = $_GET['set'];
	
} [U]else[/U] {

	$_SESSION['whattoclose'] = $_SESSION['whattoclose'] . '|' . $_GET['set'];
	
}

}

[U]if[/U]($_GET[‘undo’] > 0)
{

[U]if[/U](![U]empty[/U]($_SESSION['whattoclose'])){

	$_SESSION['whattoclose'] = str_replace("|".$_GET['undo'] , "" , $_SESSION['whattoclose']);
	$_SESSION['whattoclose'] = str_replace($_GET['undo'] , "" , $_SESSION['whattoclose']);

}

}

[U]function[/U] showTitle($id)
{

$title = [U]array[/U](
	"Navigation",
	"Login information",
	);
	
$data = $_SESSION['whattoclose'];

$not = explode( "|" , $data );
[U]if[/U](!in_array( $id , $not ))
{
	[U]echo[/U] $title[$id-1];
	[U]echo[/U] '&lt;a href="member.php?set='.$id.'"&gt; - close**&lt;/a&gt;**';
	
		
} [U]else[/U] {
	[U]echo[/U] $title[$id-1];
	[U]echo[/U] '&lt;a href="member.php?undo='.$id.'"&gt; - open**&lt;/a&gt;**';
	

}		

}

[U]function[/U] checkIt($id)
{

$data = [U]array[/U](

	'**&lt;?php

[U]echo[/U] “<p><a href='member.php?loginid=” . $_SESSION[“username”] . “’\>” . $_SESSION[“username”] . "**</a></p>";
?>

<p><a href=“member.php?change=password”>Change Password**</a></p>**
<p><a href=“member.php?change=email”>Change Email**</a>
</p>**
<p><a href=“member.php?change=account”>Close account**</a>****</p>**’,

	'**&lt;p&gt;**Welcome to the members only page '.$_SESSION['username'].'!**&lt;/p&gt;**
	**&lt;p&gt;**You are logged in [U]as[/U] '.$_SESSION['username'].' from the IP address '.$_SERVER['REMOTE_ADDR'].'**&lt;/p&gt;**',
	
	);

$str = $_SESSION['whattoclose'];

$not = explode( "|" , $str );
[U]if[/U](!in_array( $id , $not ))
{

	[U]echo[/U] '**&lt;div [U]class[/U]="table"&gt;**';
	[U]echo[/U] $data[$id-1];
	[U]echo[/U] '**&lt;/div&gt;**';

}

}

?>**

<div [U]class[/U]=“headerr”>
<? showTitle(1) ?>
</div>
<? checkIt(1) ?>
<br>
<div [U]class[/U]=“headerr”>
<? showTitle(2) ?>
</div>
<? checkIt(2) ?>

It looks like you have an extra comma at the end where you define your $data array. PHP editors with syntax highlighting are teh awesome!!!11!!1!11!

Really? Cant find it:S The error says Im missing an ‘)’ I havent edited any commans and I didnt add any either, it worked before, but once I attemp to edit the link with session everything turns to mess! :frowning:

I am pretty sure it is something to do with you loading your array. The formatting on your strings is what is causing the problem.

Why do you need to include the php opening and closing tags within your array? In order for the array to be evaluated, you have to be within a php section anyway.

Also, I noticed that you are not escaping some of your quotes properly. I would first assign the strings to a variable, and then load the arrays with those variables. It will help a great deal with readablity.

Help please? And why does it work with the link title but not inside the link then?

now here is the code rewritten to work properly:
i had to change a few things but mostly the checkit code part


<?php session_start(); 

if($_GET['set'] > 0)
{

if($_SESSION['whattoclose'] == NULL)
{

$_SESSION['whattoclose'] = $_GET['set'];

} else {

$_SESSION['whattoclose'] = $_SESSION['whattoclose'] . '|' . $_GET['set'];

}

}

if($_GET['undo'] > 0)
{

if(!empty($_SESSION['whattoclose'])){

$_SESSION['whattoclose'] = str_replace("|".$_GET['undo'] , "" , $_SESSION['whattoclose']);
$_SESSION['whattoclose'] = str_replace($_GET['undo'] , "" , $_SESSION['whattoclose']);

}

}

function showTitle($id)
{

$title = array(
"Navigation",
"Login information",
);

$data = $_SESSION['whattoclose'];

$not = explode( "|" , $data );
if(!in_array( $id , $not ))
{
echo $title[$id-1];
echo '<a href="member.php?set='.$id.'"> - close</a>';


} else {
echo $title[$id-1];
echo '<a href="member.php?undo='.$id.'"> - open</a>';


} 

}

function checkIt($id)
{

    $data = array( 
    "<p><a href='member.php?loginid=" . $_SESSION["username"] . "'\\>" . $_SESSION["username"] . "</a></p>",
    "<p><a href='member.php?change=password'>Change Password</a></p>",
    "<p><a href='member.php?change=email'>Change Email</a></p>",
    "<p><a href='member.php?change=account'>Close account</a></p>",

    "<p>Welcome to the members only page '" . $_SESSION['username'] . "'!</p>",
    "<p>You are logged in as '" . $_SESSION['username'] . "' from the IP address '" . $_SERVER['REMOTE_ADDR'] . "'</p>"

    );

    $str = $_SESSION['whattoclose'];

    $not = explode( "|" , $str );
    if(!in_array( $id , $not ))
    {
        echo '<div class="table">';
        echo $data[$id-1];
        echo '</div>';
    }
}

?>

<div class="headerr">
<? showTitle(1) ?>
</div>
<? checkIt(1) ?>
<br>
<div class="headerr">
<? showTitle(2) ?>
</div>
<? checkIt(2) ?>

Wow thanks alot! Everything works perfect now =)