2011-12-15 11 views
2

私のコードの問題はありません。

私は $sql$p_idを得るために最初に実行する必要があるが、私は $p_id = (int) $_GET['post_id'];を得ることができないように、それは、2位 $sqlを実行します。

なぜ教えていただけますか?

<?php 
error_reporting(E_ALL); 
ini_set('display_errors',1); 
include "db/db.php";  
$upload_path = "secure/content/blogpostimg"; 
if (isset($_GET['post_id']) && $_GET['post_id'] != '') { 
$p_id = (int) $_GET['post_id']; 
$sql= mysql_query("SELECT * FROM blog_post WHERE post_id = '$p_id'"); 
} else { 
$sql= mysql_query("SELECT * FROM blog_post ORDER BY post_id DESC"); 
} 
while ($rel = mysql_fetch_assoc($sql)) 
{ 
$id = $rel['post_id']; 
$sub = $rel['subject']; 
$imgname = $rel['img_name']; 
$img = $rel ['image']; 
$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 substr($msg, 0, 200)."..." . "<a href=index.php?post_id= '$p_id' 
target='_blank'>Read more</a>"; 
?> 
+0

あなたのURL/'$ _GET'はどのように見えますか? – deceze

+0

あなたは呼び出しているURLを表示できますか?そして、もしあなたが 'if(($ _ GET ['post_id']))&&(!空($ _ GET ['post_id']))' 'を使うこともできます。私の好みの方法はvarのセットを参照し、空ではありません。 –

+0

@Raubiそれは冗長です、 'if(!empty($ _ GET ['post_id']))'は同じことをします。 – deceze

答えて

2

この記事を読むことができます。

+0

ちょうどその記事を読んでくださいlastnight :) –