greens85 Posted July 20, 2009 Share Posted July 20, 2009 Hi all, I have the following code, I'm just wondering how I go about backslashing the quote so that it will display the name of the person logged in: <label>You are logged in as "<?php echo $_SESSION['username'] ?>"</label> <a href="logout.php">Logout?</a> obviously theres more code to it than this, but this is the line in question.... all this code is displayed via and echo statement, but it wont display the session name. I know this is because it isnt backslashed, but im not sure how to do this correctly... can anyone help? thanks Quote Link to comment https://forums.phpfreaks.com/topic/166633-solved-backslashing-in-php/ Share on other sites More sharing options...
rhodesa Posted July 20, 2009 Share Posted July 20, 2009 this is inside a bigger echo statement? you need to do it like this then: echo ' <label>You are logged in as "'.$_SESSION['username'].'"</label> <a href="logout.php">Logout?</a>'; Quote Link to comment https://forums.phpfreaks.com/topic/166633-solved-backslashing-in-php/#findComment-878673 Share on other sites More sharing options...
ignace Posted July 20, 2009 Share Posted July 20, 2009 If what rhodesa pointed out is not the case, then: 1) did you start session_start();? 2) does $_SESSION hold a variable username? 3) session name is not $_SESSION['username']; Quote Link to comment https://forums.phpfreaks.com/topic/166633-solved-backslashing-in-php/#findComment-878674 Share on other sites More sharing options...
greens85 Posted July 20, 2009 Author Share Posted July 20, 2009 this is inside a bigger echo statement? you need to do it like this then: echo ' <label>You are logged in as "'.$_SESSION['username'].'"</label> <a href="logout.php">Logout?</a>'; Hi Rhodesa, Yes it is inside a bigger echo statement, I tried the code you provided but it then starts to highlight as as a php keyword along with hightlighting the ampersands and also the < and /> I have provided the whole code, so hopefully to make it easier for you to see whats going on: echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="siteadminstyle.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style2 { color: #000000; font-weight: bold; } .style3 {color: #01561F} .style4 {color: #9f4e90} .style5 {color: #d70044} .style6 {color: #171970} .style7 {color: #5ab3ad} .style8 {color: #e15611} .style9 {color: #01561f} --> </style> </head> <body> <div id="container"> <div id="header"><a href="siteadmin.html"><img src="../images/AdminAreaLogo.gif" alt="Education World - Administration Area" width="268" height="98" border="0"/></a></div> <div id="loginarea"> <br/> <br/> <label>You are logged in as "<?php echo $_SESSION["username"] ?>"</label> <a href="logout.php">Logout?</a> <br/> <br/> <a href="addvacancy.php">Add Vacancy?</a> | <a href="editvacancy.php">Edit Vacancy?</a> | <a href="deletevacancy.php">Delete Vacancy?</a> </div> <br/> <div id="navigation"> <table border="0" class="main"> <tr> <td><span class="style2">Main Content</span></td> </tr> <tr> <td><a href="homepage.php" class="mainlinks">Homepage</a></td> </tr> <tr> <td><a href="#" class="mainlinks">Jobseekers</a></td> </tr> <tr> <td><a href="#" class="mainlinks">Employers</a></td> </tr> <tr> <td><a href="#" class="mainlinks">About Us</a></td> </tr> <tr> <td><a href="#" class="mainlinks">Contact Us</a></td> </tr> <tr> <td><a href="#" class="mainlinks">Terms & Conditions</a></td> </tr> <tr> <td><a href="#" class="mainlinks">Sitemap</a></td> </tr> </table> <table border="0" class="candidate"> <tr> <td></td> </tr> <tr> <td><span class="style2">Candidate Area</span></td> </tr> <tr> <td><span class="style3"><a href="#" class="earlyyears">Early Years</a></span></td> </tr> <tr> <td><span class="style4"><a href="#" class="specialneeds">Special Needs</a></span></td> </tr> <tr> <td><span class="style5"><a href="#" class="primary">Primary</a></span></td> </tr> <tr> <td><span class="style6"><a href="#" class="support">Support Staff</a></span></td> </tr> <tr> <td><span class="style7"><a href="#" class="secondary">Secondary</a></span></td> </tr> <tr> <td><span class="style8"><a href="#" class="extended">Extended Schools</a></span></td> </tr> </table> <table border="0" class="school"> <tr> <td></td> </tr> <tr> <td><span class="style2">School Area</span></td> </tr> <tr> <td><span class="style9"><a href="#" class="earlyyears">Early Years</a></span></td> </tr> <tr> <td><span class="style4"><a href="#" class="specialneeds">Special Needs</a></span></td> </tr> <tr> <td><span class="style5"><a href="#" class="primary">Primary</a></span></td> </tr> <tr> <td><span class="style6"><a href="#" class="support">Support Staff</a></span></td> </tr> <tr> <td><span class="style7"><a href="#" class="secondary">Secondary</a></span></td> </tr> <tr> <td><span class="style8"><a href="#" class="extended">Extended Schools</a></span></td> </tr> </table> </div> <div id="maincontent"> <table width="100%" border="0"> <tr> <td><strong>Your vacancy has been successfully added to the database, what would you like to do now?</strong></td> </tr> <tr> <td><a href="addvacancy.php" class="bodylinks">Add Another Vacancy?</a> | <a href="editvacancy.php" class="bodylinks">Edit Vacancy?</a> | <a href="deletevacancy.php" class="bodylinks">Delete Vacancy?</a></td> </tr> </table> </form> </div> </div> </body> </html>'; Quote Link to comment https://forums.phpfreaks.com/topic/166633-solved-backslashing-in-php/#findComment-878703 Share on other sites More sharing options...
rhodesa Posted July 20, 2009 Share Posted July 20, 2009 For large blocks of HTML you should just stop and start PHP...it makes things so much easier: <?php //Some PHP code here ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="siteadminstyle.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style2 { color: #000000; font-weight: bold; } .style3 {color: #01561F} .style4 {color: #9f4e90} .style5 {color: #d70044} .style6 {color: #171970} .style7 {color: #5ab3ad} .style8 {color: #e15611} .style9 {color: #01561f} --> </style> </head> <body> <div id="container"> <div id="header"><a href="siteadmin.html"><img src="../images/AdminAreaLogo.gif" alt="Education World - Administration Area" width="268" height="98" border="0"/></a></div> <div id="loginarea"> <br/> <br/> <label>You are logged in as "<?php echo $_SESSION["username"] ?>"</label> <a href="logout.php">Logout?</a> <br/> <br/> <a href="addvacancy.php">Add Vacancy?</a> | <a href="editvacancy.php">Edit Vacancy?</a> | <a href="deletevacancy.php">Delete Vacancy?</a> </div> <br/> <div id="navigation"> <table border="0" class="main"> <tr> <td><span class="style2">Main Content</span></td> </tr> <tr> <td><a href="homepage.php" class="mainlinks">Homepage</a></td> </tr> <tr> <td><a href="#" class="mainlinks">Jobseekers</a></td> </tr> <tr> <td><a href="#" class="mainlinks">Employers</a></td> </tr> <tr> <td><a href="#" class="mainlinks">About Us</a></td> </tr> <tr> <td><a href="#" class="mainlinks">Contact Us</a></td> </tr> <tr> <td><a href="#" class="mainlinks">Terms & Conditions</a></td> </tr> <tr> <td><a href="#" class="mainlinks">Sitemap</a></td> </tr> </table> <table border="0" class="candidate"> <tr> <td></td> </tr> <tr> <td><span class="style2">Candidate Area</span></td> </tr> <tr> <td><span class="style3"><a href="#" class="earlyyears">Early Years</a></span></td> </tr> <tr> <td><span class="style4"><a href="#" class="specialneeds">Special Needs</a></span></td> </tr> <tr> <td><span class="style5"><a href="#" class="primary">Primary</a></span></td> </tr> <tr> <td><span class="style6"><a href="#" class="support">Support Staff</a></span></td> </tr> <tr> <td><span class="style7"><a href="#" class="secondary">Secondary</a></span></td> </tr> <tr> <td><span class="style8"><a href="#" class="extended">Extended Schools</a></span></td> </tr> </table> <table border="0" class="school"> <tr> <td></td> </tr> <tr> <td><span class="style2">School Area</span></td> </tr> <tr> <td><span class="style9"><a href="#" class="earlyyears">Early Years</a></span></td> </tr> <tr> <td><span class="style4"><a href="#" class="specialneeds">Special Needs</a></span></td> </tr> <tr> <td><span class="style5"><a href="#" class="primary">Primary</a></span></td> </tr> <tr> <td><span class="style6"><a href="#" class="support">Support Staff</a></span></td> </tr> <tr> <td><span class="style7"><a href="#" class="secondary">Secondary</a></span></td> </tr> <tr> <td><span class="style8"><a href="#" class="extended">Extended Schools</a></span></td> </tr> </table> </div> <div id="maincontent"> <table width="100%" border="0"> <tr> <td><strong>Your vacancy has been successfully added to the database, what would you like to do now?</strong></td> </tr> <tr> <td><a href="addvacancy.php" class="bodylinks">Add Another Vacancy?</a> | <a href="editvacancy.php" class="bodylinks">Edit Vacancy?</a> | <a href="deletevacancy.php" class="bodylinks">Delete Vacancy?</a></td> </tr> </table> </form> </div> </div> </body> </html> <?php //More PHP code here ?> Quote Link to comment https://forums.phpfreaks.com/topic/166633-solved-backslashing-in-php/#findComment-878706 Share on other sites More sharing options...
mattal999 Posted July 20, 2009 Share Posted July 20, 2009 <?php //do session stuff ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <link href="siteadminstyle.css" rel="stylesheet" type="text/css" /> <style type="text/css"> <!-- .style2 { color: #000000; font-weight: bold; } .style3 {color: #01561F} .style4 {color: #9f4e90} .style5 {color: #d70044} .style6 {color: #171970} .style7 {color: #5ab3ad} .style8 {color: #e15611} .style9 {color: #01561f} --> </style> </head> <body> <div id="container"> <div id="header"><a href="siteadmin.html"><img src="../images/AdminAreaLogo.gif" alt="Education World - Administration Area" width="268" height="98" border="0"/></a></div> <div id="loginarea"> <br/> <br/> <label>You are logged in as "<?php echo $_SESSION["username"]; ?>"</label> <a href="logout.php">Logout?</a> <br/> <br/> <a href="addvacancy.php">Add Vacancy?</a> | <a href="editvacancy.php">Edit Vacancy?</a> | <a href="deletevacancy.php">Delete Vacancy?</a> </div> <br/> <div id="navigation"> <table border="0" class="main"> <tr> <td><span class="style2">Main Content</span></td> </tr> <tr> <td><a href="homepage.php" class="mainlinks">Homepage</a></td> </tr> <tr> <td><a href="#" class="mainlinks">Jobseekers</a></td> </tr> <tr> <td><a href="#" class="mainlinks">Employers</a></td> </tr> <tr> <td><a href="#" class="mainlinks">About Us</a></td> </tr> <tr> <td><a href="#" class="mainlinks">Contact Us</a></td> </tr> <tr> <td><a href="#" class="mainlinks">Terms & Conditions</a></td> </tr> <tr> <td><a href="#" class="mainlinks">Sitemap</a></td> </tr> </table> <table border="0" class="candidate"> <tr> <td></td> </tr> <tr> <td><span class="style2">Candidate Area</span></td> </tr> <tr> <td><span class="style3"><a href="#" class="earlyyears">Early Years</a></span></td> </tr> <tr> <td><span class="style4"><a href="#" class="specialneeds">Special Needs</a></span></td> </tr> <tr> <td><span class="style5"><a href="#" class="primary">Primary</a></span></td> </tr> <tr> <td><span class="style6"><a href="#" class="support">Support Staff</a></span></td> </tr> <tr> <td><span class="style7"><a href="#" class="secondary">Secondary</a></span></td> </tr> <tr> <td><span class="style8"><a href="#" class="extended">Extended Schools</a></span></td> </tr> </table> <table border="0" class="school"> <tr> <td></td> </tr> <tr> <td><span class="style2">School Area</span></td> </tr> <tr> <td><span class="style9"><a href="#" class="earlyyears">Early Years</a></span></td> </tr> <tr> <td><span class="style4"><a href="#" class="specialneeds">Special Needs</a></span></td> </tr> <tr> <td><span class="style5"><a href="#" class="primary">Primary</a></span></td> </tr> <tr> <td><span class="style6"><a href="#" class="support">Support Staff</a></span></td> </tr> <tr> <td><span class="style7"><a href="#" class="secondary">Secondary</a></span></td> </tr> <tr> <td><span class="style8"><a href="#" class="extended">Extended Schools</a></span></td> </tr> </table> </div> <div id="maincontent"> <table width="100%" border="0"> <tr> <td><strong>Your vacancy has been successfully added to the database, what would you like to do now?</strong></td> </tr> <tr> <td><a href="addvacancy.php" class="bodylinks">Add Another Vacancy?</a> | <a href="editvacancy.php" class="bodylinks">Edit Vacancy?</a> | <a href="deletevacancy.php" class="bodylinks">Delete Vacancy?</a></td> </tr> </table> </form> </div> </div> </body> </html> By the way, rhodesa, you missed that there was no semi-colon after $_SESSION['username'] Quote Link to comment https://forums.phpfreaks.com/topic/166633-solved-backslashing-in-php/#findComment-878708 Share on other sites More sharing options...
rhodesa Posted July 20, 2009 Share Posted July 20, 2009 By the way, rhodesa, you missed that there was no semi-colon after $_SESSION['username'] while it's good to use a semi-colon there, in this particular case it's optional Quote Link to comment https://forums.phpfreaks.com/topic/166633-solved-backslashing-in-php/#findComment-878713 Share on other sites More sharing options...
greens85 Posted July 20, 2009 Author Share Posted July 20, 2009 Thats got it, thanks for the help guys! Quote Link to comment https://forums.phpfreaks.com/topic/166633-solved-backslashing-in-php/#findComment-878724 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.