Jump to content

T_CONSTANT_ENCAPSED_STRING


ecabrera

Recommended Posts

I keep geting this i dont whats worong with it

 

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING  line 1

 

<?php
session_start();
$username = $_SESSION['username'];
?>
<?php
require "header.php";
?>
<?php if ($username){?>

<?php

echo "<br/><br/>"."Welcome <b>$username</b>, <a href='logout.php'>Logout</a href>"."<br /><br />";

?>
<?php

echo "<center><h2>Hey $username! What do you want to do?</h2></center>";

?>

<div id="ahome">

<table>
<form action="createnews" method="post">
<tr>
<td><td>
<td><td>
</tr>
<tr>
<td>Title of Article<td>
<td><input type="text" size="45" name="newstitle"/><td>
</tr>
<tr>
<td>Author of Article<td>
<td><input type="text" size="40" name="by"/><td>
</tr>
<tr>
<td>Body of Article<td>
<td><textarea cols="45" rows="25" name="newsbody"></textarea><td>
</tr>
<tr>
<td><td>
<td><input type="submit" name="submitbtn" value="Add News"/><td>
</tr>
</form></table>

</div>

<div id="rhome">


New Admin Stuff Coming Soon....<br></br>


<a href="#">Create a New Page</a><br></br>
<a href="#">Edit a Review</a>

</div>



<?php
}
else
echo "<font color='red'><center><h1>You must be logged in to view this page.</h1></center></font>";

?>
<?php
require "footer.php";
?>

Link to comment
https://forums.phpfreaks.com/topic/253153-t_constant_encapsed_string/
Share on other sites

Hi mate

 

For a start this line looks dodgy. You have an opening curly bracket but no closing bracket

 


<?php if ($username){?>

 

I keep geting this i dont whats worong with it

 

 

Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING  line 1

 

<?php
session_start();
$username = $_SESSION['username'];
?>
<?php
require "header.php";
?>
<?php if ($username){?>

<?php

echo "<br/><br/>"."Welcome <b>$username</b>, <a href='logout.php'>Logout</a href>"."<br /><br />";

?>
<?php

echo "<center><h2>Hey $username! What do you want to do?</h2></center>";

?>

<div id="ahome">

<table>
<form action="createnews" method="post">
<tr>
<td><td>
<td><td>
</tr>
<tr>
<td>Title of Article<td>
<td><input type="text" size="45" name="newstitle"/><td>
</tr>
<tr>
<td>Author of Article<td>
<td><input type="text" size="40" name="by"/><td>
</tr>
<tr>
<td>Body of Article<td>
<td><textarea cols="45" rows="25" name="newsbody"></textarea><td>
</tr>
<tr>
<td><td>
<td><input type="submit" name="submitbtn" value="Add News"/><td>
</tr>
</form></table>

</div>

<div id="rhome">


New Admin Stuff Coming Soon....<br></br>


<a href="#">Create a New Page</a><br></br>
<a href="#">Edit a Review</a>

</div>



<?php
}
else
echo "<font color='red'><center><h1>You must be logged in to view this page.</h1></center></font>";

?>
<?php
require "footer.php";
?>

Sorry didn't spot that. I really should read posts properly before posting!

 

I just ran your code without including the header or footer and with a session usname set at the top. It worked fine.

 

Is there more php in your header or footer? And are you sure the username sessions is getting set?

 

 

 

 

  its this <?php

}

else

echo "<font color='red'><center><h1>You must be logged in to view this page.</h1></center></font>";

Then since it works for me have you tried just echoing out the session variable for "username"?

 

i.e. remove all the other code and just start your session and echo out that variable to make sure it's getting passed in correctly.

 

This code works perfectly for me:

 

 


<?php
session_start();
$_SESSION['username'] = "twinky"; // set this to test the variable
$username = $_SESSION['username'];
?>
<?php
// require "header.php";
?>
<?php if ($username){?>

<?php

echo "<br/><br/>"."Welcome <b>$username</b>, <a href='logout.php'>Logout</a href>"."<br /><br />";

?>
<?php

echo "<center><h2>Hey $username! What do you want to do?</h2></center>";

?>

<div id="ahome">

<table>
<form action="createnews" method="post">
<tr>
<td><td>
<td><td>
</tr>
<tr>
<td>Title of Article<td>
<td><input type="text" size="45" name="newstitle"/><td>
</tr>
<tr>
<td>Author of Article<td>
<td><input type="text" size="40" name="by"/><td>
</tr>
<tr>
<td>Body of Article<td>
<td><textarea cols="45" rows="25" name="newsbody"></textarea><td>
</tr>
<tr>
<td><td>
<td><input type="submit" name="submitbtn" value="Add News"/><td>
</tr>
</form></table>

</div>

<div id="rhome">


New Admin Stuff Coming Soon....<br></br>


<a href="#">Create a New Page</a><br></br>
<a href="#">Edit a Review</a>

</div>



<?php
}
else
echo "<font color='red'><center><h1>You must be logged in to view this page.</h1></center></font>";

?>
<?php
//require "footer.php";
?>

 

 

its just the html header format

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.