I don't see any data in my index.php page. I use this code to get the data from mysql database with unique id, but i can't.
include "db/db.php";
$upload_path = "secure/content/blogpostimg";
<?php
if (isset($_GET['post_id']) && $_GET['post_id'] != '')
{
$p_id = (int) $_GET['post_id'];
}
$sql = mysql_query("SELECT * FROM blog_post WHERE post_id = '$pid' ORDER BY post_id
DESC ");
while ($rel = mysql_fetch_assoc($sql))
{
$id = $rel['post_id'];
$sub = $rel['subject'];
$imgname = $rel['img_name'];
$msg = $rel['message'];
$date = $rel['date'];
$poster = $rel['poster'];
$cat_name = $rel['cat_name'];
echo "<h1>". "$sub" ."</h1>". "<br/>";
echo '<img src="' . $upload_path . '/' . $imgname . '" width="200" /> ';
include_once("func.php");
echo truncate($rel['message'],"index.php","post_id",$rel['post_id']);
echo "$date " . "<b>Category:</b>
$cat_name". " ". "<b>by:</b> " . "$poster " .
"<b>Comemnts</b>[ ]" ;
}
?>
error_reporting(E_ALL);
ini_set('display_errors',1);
add these 2 lines at the very top of your code and read an answer to your question
this will let you spot those silly typos you are started with.
now, let's do the same thing to SQL
make your code like this
if (isset($_GET['post_id']))
{
$p_id = (int) $_GET['post_id'];
}
else
{
die('Required variable is not set');
}
$sql = "SELECT * FROM blog_post WHERE post_id = $p_id";
$res = mysql_query($sql) or trigger_error(mysql_error()." ".$sql);
if (!mysql_num_rows($res))
{
die("No records found");
}
You have a variable $p_id
But in query you use $pid variable name.
The first two lines of code are before the open tag: <?php