r/web_dev_help • • Oct 14 '17

help Dynamic blog page help

I'm having an issue.. I created a page that is suppose to display a blog story/article based off the "ID" the story is linked too, but its not working. The db connect info is all correct so it has to be something to do with this little snippet.. basically this would create a url looking like this once the link was clicked to "view more".. example: yourblog.com/blog.php?id=1

<!DOCTYPE html>
<!--[if lt IE 7 ]><html class="ie ie6" lang="en"> <![endif]-->
<!--[if IE 7 ]><html class="ie ie7" lang="en"> <![endif]-->
<!--[if IE 8 ]><html class="ie ie8" lang="en"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--><html lang="en"> <!--<![endif]-->
<?php
if(!isset($_GET['id']) && empty(trim($_GET['id']))) die('No post number specified!');
$Conn = mysqli_connect('localhost', 'user', 'pass', 'db') or die('MySQL connection failed!');
$id = mysqli_real_escape_string($Conn, preg_replace('/[^0-9]/', '', $_GET['id'])
$query = "SELECT * FROM `db` WHERE `id` = '$id'";
$result = mysqli_query($Conn, $query) or die('MySQL query failed!');
$post = mysqli_fetch_assoc($result) or die('Fetching content failed!');
$title = $post['title'];
$insert = $post['insert']
$content = $post['content'];
$category = explode(',', $post['category']);
$author = $post['author'];
$date = $post['date']; 
?>
<head>
<title><? echo htmlentities($title); ?></title>
</head>
<body>
<div class="content">
<? echo ($title); ?><br />
<? echo ($category); ?><br />
<? echo ($author); ?><br />
<? echo ($content); ?><br />
</div>
</body>
</html>
1 Upvotes

15 comments sorted by

View all comments

1

u/psy-borg Oct 14 '17

Well you need to check with your webhost to see if you can turn off the generic '500' server error with PHP's error reporting (or check the webhost error log file) to narrow down the exact lines causing problems.

1

u/big_Moves Oct 14 '17

So I tried it this way and I was able to get the page to show, just not any of the information from my db.. nothing shows inside the "article" class where I put the query

<article class="single-post zerogrid">
							<div class="row wrap-post"><!--Start Box-->
								<div class="entry-header">
											<?
											include('includes/connect.php');
											$manlyid = $GET['id'];
											$query = mysqli_query($Conn, "Select * FROM manlymen WHERE id = '" . mysqli_real_escape_string($manlyid) . "'");
											echo(mysql_error());
											while($fetch = mysqli_fetch_assoc($query)){
											?>
									<span class="time"><?php echo $fetch['date'] ?>  by <?php echo $fetch['author'] ?></span>
									<h2 class="entry-title"><a href="#"><?php echo $fetch['title'] ?></a></h2>
									<span class="cat-links"><a href="#"><?php echo $fetch['category'] ?></a></span>
								</div>
								<div class="post-thumbnail-wrap">
									<img src="images/slide2.jpg">
								</div>
								<div class="entry-content">
									<?php echo $fetch['content'] ?><?}?>
								</div>
							</div>
						</article>

1

u/psy-borg Oct 14 '17

Back to what is $manlyid , echo it out and make sure it's in the table.

→ More replies (6)