Reputation: 19
I have a link which links to a page which echoes out information depending on the id of the link but it is not echoing out the information. Thanks in advance for the help.
if($connect) {
mysql_selectdb('phplogin');
$id = $_GET['id'];
$query = mysql_query("SELECT * FROM forum WHERE id = '$id'");
$data = mysql_fetch_array($query);
echo "<div class='post'>" . "<div class='leftside'>" . "<h3 class='by'>" . $data['user'] . "</h3>" . "<h5 class='date'>" . $data['time'] . "</h5>" . "</div>" . "<div class='after'>" . "</div>" . "<div class='rightside'>" . "<h2 class='title'>" . htmlspecialchars($data['title']) . "</h2>" . "<p class='description'>" . htmlspecialchars($data['description']) . "</p>" . "</div>" . "<div class='clear'>" . "</div>" . "</div>";
} else {
die ('failed to connect to database');
}
Upvotes: 0
Views: 55
Reputation: 4523
Under this Query String: localhost/Website/HTML/Post.php?id=7
Try this:
if(isset($_GET['id']))
{
$id = $_GET['id'];
$query = mysql_query("SELECT * FROM forum WHERE id = '$id'");
$countQry = mysql_num_rows($query);
if($countQry>0)
{
$data = mysql_fetch_array($query);
//-- Fetch your Data here ---//
}
else
{
echo "No record found.";
}
}
else
{
echo "Invalid Id";
}
Your MYSQL Connection should be like this :
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
Upvotes: 1