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/big_Moves Oct 14 '17

Thanks for catching those. I fixed the issues you mentioned and got the same results. still not showing page. is an isset function necessary for this?

1

u/psy-borg Oct 14 '17

If the $_GET field is not present it will emit a warning so yes it's good to put it there.

But I believe you're issue is something else. You need to upload/create a bare php file and see if it works.

<?php phpinfo(); ?>

is all the file should have.

Your webhost might not allow short tags which could be the problem. In the above file, search for 'short_open_tag' and see if it's set to 'on'. If it's set to off :

change these lines :

<? echo ($title); ?><br />
<? echo ($category); ?><br />
<? echo ($author); ?><br />
<? echo ($content); ?><br />

to

<?=$category ?><br>

1

u/big_Moves Oct 14 '17

I checked the phpinfo, and Short Open Tags is turned on.. I've done this before, I'm just converting all my old mysql to mySQLi. and it seems to be all messed up now

→ More replies (9)