ecabrera Posted December 14, 2011 Share Posted December 14, 2011 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/253153-t_constant_encapsed_string/ Share on other sites More sharing options...
Drongo_III Posted December 14, 2011 Share Posted December 14, 2011 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"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/253153-t_constant_encapsed_string/#findComment-1297786 Share on other sites More sharing options...
ecabrera Posted December 14, 2011 Author Share Posted December 14, 2011 its this <?php } else echo "<font color='red'><center><h1>You must be logged in to view this page.</h1></center></font>"; Quote Link to comment https://forums.phpfreaks.com/topic/253153-t_constant_encapsed_string/#findComment-1297787 Share on other sites More sharing options...
Drongo_III Posted December 14, 2011 Share Posted December 14, 2011 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>"; Quote Link to comment https://forums.phpfreaks.com/topic/253153-t_constant_encapsed_string/#findComment-1297790 Share on other sites More sharing options...
ecabrera Posted December 14, 2011 Author Share Posted December 14, 2011 its just the html header format Quote Link to comment https://forums.phpfreaks.com/topic/253153-t_constant_encapsed_string/#findComment-1297792 Share on other sites More sharing options...
Drongo_III Posted December 14, 2011 Share Posted December 14, 2011 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 Quote Link to comment https://forums.phpfreaks.com/topic/253153-t_constant_encapsed_string/#findComment-1297793 Share on other sites More sharing options...
ecabrera Posted December 14, 2011 Author Share Posted December 14, 2011 how would i set up a seesion Quote Link to comment https://forums.phpfreaks.com/topic/253153-t_constant_encapsed_string/#findComment-1297798 Share on other sites More sharing options...
Drongo_III Posted December 14, 2011 Share Posted December 14, 2011 sorry i just meant start the session with session_start() like you have and then echo out the $_session['username'] to ensure a value is actually being passed to it. how would i set up a seesion Quote Link to comment https://forums.phpfreaks.com/topic/253153-t_constant_encapsed_string/#findComment-1297802 Share on other sites More sharing options...
kicken Posted December 14, 2011 Share Posted December 14, 2011 Are you sure the error is not in say your header.php or footer.php files? Quote Link to comment https://forums.phpfreaks.com/topic/253153-t_constant_encapsed_string/#findComment-1297922 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.