Jump to content

Not displaying data, and in the wrong place?


3raser

Recommended Posts

<?php
include_once("includes/config.php");

if(!$_GET['id'] && $_POST['id'])
{
$id = mysql_real_escape_string($_POST['id']);
}
elseif($_GET['id'] && !$_POST['id'])
{
$id = mysql_real_escape_string($_GET['id']);
}
else
{

}

if(!$id)
{
$content = "Sorry, you have not selected a skin to view.";
}
else
{
$extract_information = mysql_query("SELECT title,username,downloads,views,id FROM skins WHERE id = '$id' LIMIT 1");

if(mysql_num_rows($extract_information) == 0)
{
	$content = "Sorry, no skin exists with this ID.";
}
else
{
	$extract = mysql_fetch_assoc($extract_information);

	function displayBody() 
	{
		mysql_query("UPDATE skins SET views = views + 1 WHERE id = '$id'");

		echo $extract['title']. ", by ". $extract['username'] .".";
	}

	if(!$extract['password'])
	{
		$content = displayBody();
	}
	elseif(!$password)
	{
		$content = "<br/><br/><div id='header'>Password</div> <form action='view.php' method='POST'><input type='password' name='password'>
		<input type='submit' value='View'></form>";
	}
	else
	{
		if($password != $extract['password'])
		{
			$content = "You have entered in an incorrect password. <a href='view.php?id=". $id ."'>Try Again</a> or <a href='index.php'>Home</a>.";
		}
		else
		{
			$content = displayBody();
		}
	}
}
}

?>
<html>
<head>
<title><?php $title; ?></title>
<link rel="stylesheet" type="text/css" href="theme/style.css" />
</head>
<body>
<div id="header">
MCSkins
</div>

<?php echo $content; ?>
</table>
</center>

</body>
</html>

 

In the code above, the function does not include the data properly as seen here: http://stonedknights.net46.net/view.php?id=2

 

And, why is the information above the black bar/title? In the code, you can see $content is echo'ed below the div id. So, why does the text appear above it?

You're echoing the title instead of storing it in a variable, and it looks like it isn't getting a value anyhow. If you look at the html source, you'll see it's echoed even before the opening <html> tag.

 

echo $extract['title']. ", by ". $extract['username'] .".";

This is going to ouput before your HTML because that's the document flow.

 

function displayBody() {
mysql_query("UPDATE skins SET views = views + 1 WHERE id = '$id'");	
echo $extract['title']. ", by ". $extract['username'] ."."; }

 

would this not do the trick?

 

function displayBody() {
mysql_query("UPDATE skins SET views = views + 1 WHERE id = '$id'");	
$content = $extract['title']. ", by ". $extract['username'] ."."; }

 

 

It should be:

function displayBody() {
mysql_query("UPDATE skins SET views = views + 1 WHERE id = '$id'");	
return $extract['title']. ", by ". $extract['username'] ."."; }

 

You are then setting $contents to the returned data from the function.

 

HERE:

	
$content = displayBody();

It should be:

function displayBody() {
mysql_query("UPDATE skins SET views = views + 1 WHERE id = '$id'");	
return $extract['title']. ", by ". $extract['username'] ."."; }

 

You are then setting $contents to the returned data from the function.

 

HERE:

	
$content = displayBody();

 

Thanks, that worked.

 

But now all it says is:

 

, by .

 

And it also doesn't run the query in the function.

Sorry, I focused on the return part, and left out the other parts.

 

function displayBody($id) {
  $result = mysql_query("UPDATE skins SET views = views + 1 WHERE id = '$id'");
  return true;
}

 

Then:

$content = (displayBody($id)) ? $extract['title']. ", by ". $extract['username'] ."." : NULL;

 

You ran out of scope with the function, you must put ID into the function scope.  As well, the $extract array is out of scope with the function.  Since there is no reason to send an argument to the function just to return it, handle the $extracts outside of the function, based on how the function acts.  So, we return the function as true, to enable us to decide which string should display.

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.