3raser Posted March 28, 2011 Share Posted March 28, 2011 <?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? Quote Link to comment https://forums.phpfreaks.com/topic/231909-not-displaying-data-and-in-the-wrong-place/ Share on other sites More sharing options...
Skewled Posted March 28, 2011 Share Posted March 28, 2011 Move this code into the actual <head> tag <div id="header"> MCSkins </div> that's just my suggestion. Quote Link to comment https://forums.phpfreaks.com/topic/231909-not-displaying-data-and-in-the-wrong-place/#findComment-1193091 Share on other sites More sharing options...
3raser Posted March 28, 2011 Author Share Posted March 28, 2011 Move this code into the actual <head> tag <div id="header"> MCSkins </div> that's just my suggestion. It doesn't belong in head. Quote Link to comment https://forums.phpfreaks.com/topic/231909-not-displaying-data-and-in-the-wrong-place/#findComment-1193092 Share on other sites More sharing options...
Skewled Posted March 28, 2011 Share Posted March 28, 2011 I'm sorry been awake for way too long lol. Quote Link to comment https://forums.phpfreaks.com/topic/231909-not-displaying-data-and-in-the-wrong-place/#findComment-1193093 Share on other sites More sharing options...
Pikachu2000 Posted March 28, 2011 Share Posted March 28, 2011 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'] ."."; Quote Link to comment https://forums.phpfreaks.com/topic/231909-not-displaying-data-and-in-the-wrong-place/#findComment-1193095 Share on other sites More sharing options...
Skewled Posted March 28, 2011 Share Posted March 28, 2011 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'] ."."; } Quote Link to comment https://forums.phpfreaks.com/topic/231909-not-displaying-data-and-in-the-wrong-place/#findComment-1193096 Share on other sites More sharing options...
3raser Posted March 28, 2011 Author Share Posted March 28, 2011 When changed to this: function displayBody() { mysql_query("UPDATE skins SET views = views + 1 WHERE id = '$id'"); $content = $extract['title']. ", by ". $extract['username'] ."."; } Nothing comes up. -.- Quote Link to comment https://forums.phpfreaks.com/topic/231909-not-displaying-data-and-in-the-wrong-place/#findComment-1193099 Share on other sites More sharing options...
jcbones Posted March 28, 2011 Share Posted March 28, 2011 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(); Quote Link to comment https://forums.phpfreaks.com/topic/231909-not-displaying-data-and-in-the-wrong-place/#findComment-1193104 Share on other sites More sharing options...
3raser Posted March 28, 2011 Author Share Posted March 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/231909-not-displaying-data-and-in-the-wrong-place/#findComment-1193106 Share on other sites More sharing options...
jcbones Posted March 28, 2011 Share Posted March 28, 2011 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. Quote Link to comment https://forums.phpfreaks.com/topic/231909-not-displaying-data-and-in-the-wrong-place/#findComment-1193112 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.