JackCode Posted January 6, 2014 Share Posted January 6, 2014 <?php if(isset($_SESSION['id']) && $_SESSION['id'] > 0) { echo "<li><a href='profile.php?=$_SESSION['id']'>My profile</a></li>"; } Hello, my quotation marks don't link up to the right ones, anyone know how to fix this issue? the red ones need to match up Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/ Share on other sites More sharing options...
Ch0cu3r Posted January 6, 2014 Share Posted January 6, 2014 Wrap $_SESSION['id'] in curly braces echo "<li><a href='profile.php?={$_SESSION['id']}'>My profile</a></li>"; Or concatenate echo "<li><a href='profile.php?=".$_SESSION['id']."'>My profile</a></li>"; Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464137 Share on other sites More sharing options...
JIXO Posted January 6, 2014 Share Posted January 6, 2014 You can also escape : echo "<li><a href='profile.php?=$_SESSION[\'id\']'>My profile</a></li>"; Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464138 Share on other sites More sharing options...
JackCode Posted January 6, 2014 Author Share Posted January 6, 2014 Thank you very much both. I have done this and the error has gone, but now so has the link... Any ideas? Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464140 Share on other sites More sharing options...
Ch0cu3r Posted January 6, 2014 Share Posted January 6, 2014 On 1/6/2014 at 9:24 PM, JIXO said: You can also escape : echo "<li><a href='profile.php?=$_SESSION[\'id\']'>My profile</a></li>"; No, that wont work either. When using complex variable name like an associative array within a sting you need to wrap it within curly braces. You cannot escape the quotes for the variable The only time you'd escape quotes would be for the HTML, eg echo "<li><a href=\"profile.php?={$_SESSION['id']}\">My profile</a></li>"; // ^---- escape double quotes ----^ Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464143 Share on other sites More sharing options...
JackCode Posted January 6, 2014 Author Share Posted January 6, 2014 Thank you I have solved the single/double quote problem but now my link has disappeared. Can anyone explain why? Thanks Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464145 Share on other sites More sharing options...
Ch0cu3r Posted January 6, 2014 Share Posted January 6, 2014 On 1/6/2014 at 9:40 PM, JackCode said: Thank you I have solved the single/double quote problem but now my link has disappeared. Can anyone explain why? Thanks My code suggestions should work fine. What di d you change your code to? Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464147 Share on other sites More sharing options...
JackCode Posted January 6, 2014 Author Share Posted January 6, 2014 <?php if(isset($_SESSION['id']) && $_SESSION['id'] > 0) { echo "<li><a href='profile.php?=$_SESSION{['id']}'>My profile</a></li>"; } ?> The link has now completely disappeared but in my IDE it says there's no errors. Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464149 Share on other sites More sharing options...
Dowlat Posted January 6, 2014 Share Posted January 6, 2014 On 1/6/2014 at 9:40 PM, JackCode said: Thank you I have solved the single/double quote problem but now my link has disappeared. Can anyone explain why? Thanks Your conditional expression is not returning true. Print the contents of $_SESSION and check if it has been properly initialized in your code. Also Jack, make it good habit to always encapsulate your code with the CODE TAGS provided in the editor. Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464150 Share on other sites More sharing options...
JackCode Posted January 6, 2014 Author Share Posted January 6, 2014 On 1/6/2014 at 9:45 PM, Dowlat said: Your conditional expression is not returning true. Print the contents of $_SESSION and check if it has been properly initialized in your code. Can you show me how to return it true and initialize. Sorry I am new to PHP. Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464151 Share on other sites More sharing options...
Ch0cu3r Posted January 6, 2014 Share Posted January 6, 2014 On 1/6/2014 at 9:45 PM, JackCode said: <?php if(isset($_SESSION['id']) && $_SESSION['id'] > 0) { echo "<li><a href='profile.php?=$_SESSION{['id']}'>My profile</a></li>"; } ?> The link has now completely disappeared but in my IDE it says there's no errors. The curly braces need to go around the whole variable, as {$_SESSION['id']} echo "<li><a href='profile.php?={$_SESSION['id']}'>My profile</a></li>"; // ^---- brace ----^ Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464152 Share on other sites More sharing options...
JackCode Posted January 6, 2014 Author Share Posted January 6, 2014 Done that, makes no difference. Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464154 Share on other sites More sharing options...
Ch0cu3r Posted January 6, 2014 Share Posted January 6, 2014 Well that is the correct syntax, If your link is not appearing your code might be outputting invalid HTML which is causing the link to not appear. When you run your PHP code check the HTML source code via Right click > view source. Can you spot an HTML error? Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464156 Share on other sites More sharing options...
JackCode Posted January 6, 2014 Author Share Posted January 6, 2014 On 1/6/2014 at 9:56 PM, Ch0cu3r said: Well that is the correct syntax, If your link is not appearing your code might be outputting invalid HTML which is causing the link to not appear. When you run your PHP code check the HTML source code via Right click > view source. Can you spot an HTML error? There is definitely not an error because I tried it in a separate document named test.php and nothing appeared. Basically what I'm trying to do is create a universal link from a page to my profile.php page. Any advice on what I can use alternatively? Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464157 Share on other sites More sharing options...
Ch0cu3r Posted January 6, 2014 Share Posted January 6, 2014 Quote There is definitely not an error because I tried it in a separate document named test.php and nothing appeared. By this do you mean you get a completely blank page? If you do, then check your servers error log for php errors. Or turn error reporting on at the top of your PHP script. ini_set('display_errrors', 1); error_reporting(E_ALL); Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464158 Share on other sites More sharing options...
JackCode Posted January 6, 2014 Author Share Posted January 6, 2014 On 1/6/2014 at 10:04 PM, Ch0cu3r said: By this do you mean you get a completely blank page? If you do, then check your servers error log for php errors. Or turn error reporting on at the top of your PHP script. ini_set('display_errrors', 1); error_reporting(E_ALL); No I don't mean that I mean there is no errors with the HTML because I tried the PHP in a page with no other code and when I tested it there still was no link so there must be an error with the PHP code causing it to not appear. Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464159 Share on other sites More sharing options...
Ch0cu3r Posted January 6, 2014 Share Posted January 6, 2014 Can you tell me how you are testing the code. The code I have posted is free of any PHP/HTML errors and will output a link just fine. Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464160 Share on other sites More sharing options...
JackCode Posted January 6, 2014 Author Share Posted January 6, 2014 Using a web server: my website is backupransack.freeoda.com If you look on the home page then game page the home page is missing the 'my profile' link. Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464162 Share on other sites More sharing options...
Ch0cu3r Posted January 6, 2014 Share Posted January 6, 2014 Your link is visible! The problem is $_SESSION['id'] value has not been outputted, most probably due this variable not being defined before hand, has no value or you have not started the session. What is the output of <?php printf('<pre>%s</pre>', print_r($_SESSION, true)); ?> Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464163 Share on other sites More sharing options...
Dowlat Posted January 6, 2014 Share Posted January 6, 2014 On 1/6/2014 at 10:16 PM, JackCode said: Using a web server: my website is backupransack.freeoda.com If you look on the home page then game page the home page is missing the 'my profile' link. Jackcode, The only way the profile link will be printed entirely is if the conditional statement returns (BOOL) True. If your link is visible then thats a different story, your problem lies with the html. If your conditional statement is true, then the ID should print a number more than 0, and it is set. so I don't see how your url could be empty. Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464164 Share on other sites More sharing options...
JackCode Posted January 6, 2014 Author Share Posted January 6, 2014 Ch0cu3r I have sent you a message with my code. Please reply? Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464165 Share on other sites More sharing options...
JackCode Posted January 6, 2014 Author Share Posted January 6, 2014 On 1/6/2014 at 10:21 PM, Ch0cu3r said: Your link is visible! The problem is $_SESSION['id'] value has not been outputted, most probably due this variable not being defined before hand, has no value or you have not started the session. What is the output of <?php printf('<pre>%s</pre>', print_r($_SESSION, true)); ?> nothing. Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464167 Share on other sites More sharing options...
Dowlat Posted January 6, 2014 Share Posted January 6, 2014 On 1/6/2014 at 10:29 PM, JackCode said: nothing. Post your code, where you are setting the sessions. Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464168 Share on other sites More sharing options...
Ch0cu3r Posted January 6, 2014 Share Posted January 6, 2014 On 1/6/2014 at 10:29 PM, JackCode said: nothing. You was logged into your site when you ran my code? Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464170 Share on other sites More sharing options...
JackCode Posted January 6, 2014 Author Share Posted January 6, 2014 I put it under my link and when I log in it says: array [username] => Jack [id] => 2 Link to comment https://forums.phpfreaks.com/topic/285150-php-quotations-dont-match-up/#findComment-1464172 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.