Jump to content

Bad Display when script tag gets added


The Little Guy

Recommended Posts

When I use this code on my page, it displays perfectly fine.

<?php
echo '
<div class="content">';
	$sql = mysql_query("SELECT * FROM feed WHERE owner = '$_id' ORDER BY `date` DESC LIMIT 1")or die(mysql_error());
	if(mysql_num_rows($sql) == 1){
		$row = mysql_fetch_array($sql);
		$status = htmlentities($row['status']);
	}else{
		$status = 'What\'s going on?';
	}
	echo '<div class="fontbig" id="status">
	<a href="javascript:void(0);" onclick="setStatus(parentNode.id,\''.$_first.'\');">'.$_first.' '.$status.'</a>
	</div>
</div>
?>

 

When I add a script tag like the following, it gets all messed up, and doesn't display correctly...

 

<?php
echo '
<div class="content">';
	$sql = mysql_query("SELECT * FROM feed WHERE owner = '$_id' ORDER BY `date` DESC LIMIT 1")or die(mysql_error());
	if(mysql_num_rows($sql) == 1){
		$row = mysql_fetch_array($sql);
		$status = htmlentities($row['status']);
	}else{
		$status = 'What\'s going on?';
	}
	echo '<div class="fontbig" id="status">
	<a href="javascript:void(0);" onclick="setStatus(parentNode.id,\''.$_first.'\');">'.$_first.' '.$status.'</a>
	</div>
</div><script type="text/javascript">myStatus=\''.$status.'\';</script>';
?>

 

I have ran my code through the w3 HTML validator, and it validates as valid HTML, so why does it do this?

 

The following attachment shows the problem, the left image is how it should look, and the one on the right is what happens after placing the script tag.

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/150836-bad-display-when-script-tag-gets-added/
Share on other sites

that seems very odd. Your first script seems to be treating the html as php code at the bottem yet it displays correctly. The second is treating it correctly as html yet doesnt display correctly...

 

Where you have this on your second script:

(parentNode.id,\''.$_first.'\');">'.$_first.' '.$status.'</a>

 

try replacing it with this:

(parentNode.id,\''.$_first.'\');">'.$_first.' '.$status.</a>

As that seems to be how the top code is working...

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.