EchoFool Posted August 18, 2009 Share Posted August 18, 2009 I've never seen this happen before and its totally above my knowledge so maybe some one else can explain but like one line of my php script decides to echo and display even though theres nothing wrong with it... heres the script : <?php If(isset($_SESSION['Current_User'])){?><a href="contactus.php">Contact Us</a> |<?php} If(isset($_SESSION['Current_User']) && !(isset($_SESSION['Staff']))){ $Get = mysql_query("SELECT UserID FROM staff WHERE UserID='{$_SESSION['Current_User']}'") Or die(mysql_error()); If(mysql_num_rows($Get) > 0){ //FROM HERE $_SESSION['Staff'] = 1; }Else{ $_SESSION['Staff'] = NULL; } } If(isset($_SESSION['Staff']) && $_SESSION['Staff'] == 1){ //TO HERE ECHOS ?> <a href="staffpanel.php">Staff Panel</a> <?php }?> On my browser this is what i see: Contact Us | 0){ $_SESSION['Staff'] = 1; }Else{ $_SESSION['Staff'] = NULL; } } If(isset($_SESSION['Staff']) && $_SESSION['Staff'] == 1){ ?> Staff Panel I just don't get why it makes no sense! Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/ Share on other sites More sharing options...
mikesta707 Posted August 18, 2009 Share Posted August 18, 2009 thats interesting... it may be because your php tags and your closing brackets don't have a space between them. try adding a spce between <?php and } Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901303 Share on other sites More sharing options...
Giri J Posted August 18, 2009 Share Posted August 18, 2009 Hi, I'm not sure if it works for you. But try echoing the html a tags and just use 1 php close and open. eg: <?php ...some code if (true) echo "<a href=\"true.html\"">True</a>"; else echo "<a href=\"false.html\"">False</a>"; ...some php code ?> Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901306 Share on other sites More sharing options...
EchoFool Posted August 18, 2009 Author Share Posted August 18, 2009 Tried both your ideas, didn't change much Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901316 Share on other sites More sharing options...
mikesta707 Posted August 18, 2009 Share Posted August 18, 2009 and you get no errors? it just echos the script? Thats one of the strangest problems i've ever seen on these forums... I just tested some code very similar to yours and it works... maybe there is a problem with your server Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901320 Share on other sites More sharing options...
EchoFool Posted August 18, 2009 Author Share Posted August 18, 2009 i was wondering if it was related to my php setup as its a recent install on my localhost but i don't know what setting might cause this kinda thing EDIT: I also get unexpected end even when the same script uploaded to an online server, it gives no error.. how odd... must be my setup.. any idea? Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901324 Share on other sites More sharing options...
mikesta707 Posted August 18, 2009 Share Posted August 18, 2009 the unexpected end is probably from your closing bracket being connected to your opening php tag. Well when I copied and pasted your code to my server it didn't work until I created a space. this did not work: If(isset($df)){?><a href="contactus.php">Contact Us</a> |<?php} this did If(isset($df)){ ?><a href="contactus.php">Contact Us</a> |<?php } Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901330 Share on other sites More sharing options...
EchoFool Posted August 18, 2009 Author Share Posted August 18, 2009 I did that and i got this: Parse error: syntax error, unexpected '}' in C:\xampp\htdocs\maxvotes\header\header.php on line 38 <a href="userpanel.php"> <?php If(isset($_SESSION['Current_User'])){ ?> User Panel <?php }Else{ ?> Login/Register <?php } ?> </a> I am convinced its winding me up! Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901336 Share on other sites More sharing options...
mikesta707 Posted August 18, 2009 Share Posted August 18, 2009 which line is line 38? Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901337 Share on other sites More sharing options...
oni-kun Posted August 18, 2009 Share Posted August 18, 2009 i was wondering if it was related to my php setup as its a recent install on my localhost but i don't know what setting might cause this kinda thing EDIT: I also get unexpected end even when the same script uploaded to an online server, it gives no error.. how odd... must be my setup.. any idea? Try this code. <?php If(isset($_SESSION['Current_User'])) { echo '<a href="contactus.php">Contact Us</a> |'; } If(isset($_SESSION['Current_User']) && !(isset($_SESSION['Staff']))){ $Get = mysql_query("SELECT UserID FROM staff WHERE UserID='".$_SESSION['Current_User']."'") or die(mysql_error(); If(mysql_num_rows($Get) > 0){ //FROM HERE $_SESSION['Staff'] = 1; }Else{ $_SESSION['Staff'] = NULL; } } If(isset($_SESSION['Staff']) && $_SESSION['Staff'] == 1) { echo '<a href="staffpanel.php">Staff Panel</a>'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901338 Share on other sites More sharing options...
EchoFool Posted August 18, 2009 Author Share Posted August 18, 2009 which line is line 38? That 5 lines was line 38 i just broke it up so its easier to read on the forum Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901341 Share on other sites More sharing options...
EchoFool Posted August 18, 2009 Author Share Posted August 18, 2009 i was wondering if it was related to my php setup as its a recent install on my localhost but i don't know what setting might cause this kinda thing EDIT: I also get unexpected end even when the same script uploaded to an online server, it gives no error.. how odd... must be my setup.. any idea? Try this code. <?php If(isset($_SESSION['Current_User'])) { echo '<a href="contactus.php">Contact Us</a> |'; } If(isset($_SESSION['Current_User']) && !(isset($_SESSION['Staff']))){ $Get = mysql_query("SELECT UserID FROM staff WHERE UserID='".$_SESSION['Current_User']."'") or die(mysql_error(); If(mysql_num_rows($Get) > 0){ //FROM HERE $_SESSION['Staff'] = 1; }Else{ $_SESSION['Staff'] = NULL; } } If(isset($_SESSION['Staff']) && $_SESSION['Staff'] == 1) { echo '<a href="staffpanel.php">Staff Panel</a>'; } ?> Yup tried that it still displayed the : $_SESSION['Staff'] = 1; }Else{ $_SESSION['Staff'] = NULL; Part =/ Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901343 Share on other sites More sharing options...
mikesta707 Posted August 18, 2009 Share Posted August 18, 2009 I see. I would suggest, rather than breaking the PHP tags and putting in static html, just echoing the whole HTML itself in PHPO, (like some people have done here) I don't really see a problem in your code, so unless some obvious syntax error is eluding us all, I don't really know whats wrong EDIT: yeah im thinking its your PHP setup or something, because I can't see anything wrong with those lines Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901345 Share on other sites More sharing options...
MatthewJ Posted August 18, 2009 Share Posted August 18, 2009 Yeah... few things... use an editor with syntax highlighting and try not to get so tricky with opening and closing php tags all the time... it makes sense in some situations, but this is pretty hard to read. <?php if(isset($_SESSION['Current_User'])) { ?> <a href="contactus.php">Contact Us</a> | <?php } ?> <?php if(isset($_SESSION['Current_User']) && !(isset($_SESSION['Staff']))) { $Get = mysql_query("SELECT UserID FROM staff WHERE UserID='{$_SESSION['Current_User']}'") or die(mysql_error()); if(mysql_num_rows($Get) > 0){ //FROM HERE $_SESSION['Staff'] = 1; }Else{ $_SESSION['Staff'] = NULL; } } if(isset($_SESSION['Staff']) && $_SESSION['Staff'] == 1){ //TO HERE ECHOS ?> <a href="staffpanel.php">Staff Panel</a> <?php } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901346 Share on other sites More sharing options...
EchoFool Posted August 18, 2009 Author Share Posted August 18, 2009 I see. I would suggest, rather than breaking the PHP tags and putting in static html, just echoing the whole HTML itself in PHPO, (like some people have done here) I don't really see a problem in your code, so unless some obvious syntax error is eluding us all, I don't really know whats wrong Can't be a syntax because when uploaded to my online server its got no errors... its only on my localhost so maybe its my php settings =/ ? I open and close tags because my editor (notepad++) makes a nice clear colour difference with html and PHP so its better than echo ' html '; as it blends in too much Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901348 Share on other sites More sharing options...
MatthewJ Posted August 18, 2009 Share Posted August 18, 2009 Seems to be a lot of opens and closes to handle two echoes... <?php if(isset($_SESSION['Current_User'])) { echo "<a href='contactus.php'>Contact Us</a> |"; } if(isset($_SESSION['Current_User']) && !(isset($_SESSION['Staff']))) { $Get = mysql_query("SELECT UserID FROM staff WHERE UserID='{$_SESSION['Current_User']}'") or die(mysql_error()); if(mysql_num_rows($Get) > 0){ //FROM HERE $_SESSION['Staff'] = 1; }Else{ $_SESSION['Staff'] = NULL; } } if(isset($_SESSION['Staff']) && $_SESSION['Staff'] == 1){ //TO HERE ECHOS echo "<a href='staffpanel.php'>Staff Panel</a>"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901351 Share on other sites More sharing options...
EchoFool Posted August 18, 2009 Author Share Posted August 18, 2009 Fixed the problem woo ! For some unknown reason i needed short open tags ON ...even though i used not short tags =/ Thanks everyone for trying Quote Link to comment https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/#findComment-901355 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.