tomm098 Posted May 10, 2010 Share Posted May 10, 2010 Hey all I have a problem with echoing a PHP dynamic link. This is the link i need to echo. It works fine as a HTML link but as soon as i put it in the PHP echo code it stuffs up. I think it needs a different syntax or something. <a href="userstats.php?User=<?php echo ($_COOKIE ['Username']) ?>"><?php echo ($_COOKIE['Username']) ?></a> I must PHP echo it like so: <?php echo "THE LINK ABOVE" any help would be greatly appreciated.. thanks Quote Link to comment https://forums.phpfreaks.com/topic/201278-echo-dynamic-link/ Share on other sites More sharing options...
kenrbnsn Posted May 10, 2010 Share Posted May 10, 2010 What do you mean my "Stuffs up"? Do you get any error messages? Ken Quote Link to comment https://forums.phpfreaks.com/topic/201278-echo-dynamic-link/#findComment-1055980 Share on other sites More sharing options...
tomm098 Posted May 10, 2010 Author Share Posted May 10, 2010 Yer. sorry. Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home2/whatsong/public_html/test.php on line 246 Quote Link to comment https://forums.phpfreaks.com/topic/201278-echo-dynamic-link/#findComment-1055981 Share on other sites More sharing options...
cleibesouza Posted May 10, 2010 Share Posted May 10, 2010 Missing ; after echo Quote Link to comment https://forums.phpfreaks.com/topic/201278-echo-dynamic-link/#findComment-1055985 Share on other sites More sharing options...
kenrbnsn Posted May 10, 2010 Share Posted May 10, 2010 Please post a few lines before and after that line. The error could be in a previous PHP line, but the parser couldn't see that until it hit this line. No, since the "echo" is terminated by the closing "?>" that line doesn't need a ";" Ken Quote Link to comment https://forums.phpfreaks.com/topic/201278-echo-dynamic-link/#findComment-1055987 Share on other sites More sharing options...
tomm098 Posted May 10, 2010 Author Share Posted May 10, 2010 This is my entire code, but im fairly sure its the link that is the problem because it works fine until i replace the first echo. I'm trying to replace the "($_COOKIE['Username']) after //user is logged in. with the first <a href link <p><a href="userstats.php?User=<?php echo ($_COOKIE ['Username']) ?>"><?php echo ($_COOKIE['Username']) ?></a></p> <p> <?php if($_SESSION['Username'] || $_COOKIE['Username']) { //user is logged in echo ($_COOKIE['Username'])."<br /"."<a href=\"Logout.php\">Logout</a>"; } else { //user is not logged in echo "<a href=\"/logreg/Login.php\">Login</a>"."<br />"."<a href=\"/logreg/Registration.php\">Register</a>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/201278-echo-dynamic-link/#findComment-1055999 Share on other sites More sharing options...
ignace Posted May 10, 2010 Share Posted May 10, 2010 http://www.php.net/manual/en/tokens.php Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home2/whatsong/public_html/test.php on line 246 makes me believe you tried: <?php echo "<a href="userstats.php?User=<?php echo ($_COOKIE ['Username']) ?>"><?php echo ($_COOKIE['Username']) ?></a>" ?> Edit: remove the space after $_COOKIE Quote Link to comment https://forums.phpfreaks.com/topic/201278-echo-dynamic-link/#findComment-1056001 Share on other sites More sharing options...
tomm098 Posted May 10, 2010 Author Share Posted May 10, 2010 Hmm I get the same error. Is there a way to make that link a variable. then simply write the variable into the PHP? Quote Link to comment https://forums.phpfreaks.com/topic/201278-echo-dynamic-link/#findComment-1056015 Share on other sites More sharing options...
kenrbnsn Posted May 10, 2010 Share Posted May 10, 2010 That can't be your entire script, since the error says it's occurring on line 246. Put <?php echo '<pre>' . print_r($_COOKIE,true) . '</pre>'; ?> at the start of your script. What is displayed? Ken Quote Link to comment https://forums.phpfreaks.com/topic/201278-echo-dynamic-link/#findComment-1056016 Share on other sites More sharing options...
tomm098 Posted May 10, 2010 Author Share Posted May 10, 2010 I dont think i have a script. but this is what was returned Array ( [__utma] => 213566930.929732667496323600.1250559715.1273507737.1273513206.669 [__utmb] => 213566930.12.10.1273513206 [__utmc] => 213566930 [__utmz] => 213566930.1272378641.588.9.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=the boat that rocked song [userId] => 59 [username] => tomm098 [_csuid] => 4a36424d10dbcd31 [phpSESSID] => gcjcbqlbjlo8vmfjnueeqlgf17 [user] => MM_Username ) Quote Link to comment https://forums.phpfreaks.com/topic/201278-echo-dynamic-link/#findComment-1056024 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.