Jump to content

[SOLVED] Backslashing in PHP


greens85

Recommended Posts

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

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

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
?>

Link to comment
Share on other sites

<?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']

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.