Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/170886-solved-script-displayed-as-html/
Share on other sites

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

 

?>

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?

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 }

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!

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

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 =/

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

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

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 :(

 

 

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>";
}

?>

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.