Jump to content

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

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.