2013-07-13 6 views
0

제목이 읽히면서 "주제를 표시 할 수 없습니다. 나중에 다시 시도하십시오."라는 메시지가 나타납니다. 오류 메시지가 있지만 데이터를 내 mysql 테이블에 잘 삽입하고있다,하지만 왜 그들이 표시되지 않습니다 알아낼 수 없다, 여기에 내 결과 페이지입니다.MySQL 결과가 데이터베이스에 삽입되었지만 결과가 표시되지 않음

<?php 
include 'core/init.php'; 
include 'includes/overall/header.php'; 

$sql = "SELECT 'topic_id', 'topic_subject', 'category', 'sub_category', 'posted_by', 'posted', 'view', 'reply' FROM `topics` 
    WHERE topics.topic_id = " . mysql_real_escape_string($_GET['id']); 

$result = mysql_query($sql); 

if(!$result) 
{ 
echo 'The topic could not be displayed, please try again later.'; 
} 
else 
{ 
if(mysql_num_rows($result) == 0) 
{ 
    echo 'This topic doesn&prime;t exist.'; 
} 
else 
{ 
    while($row = mysql_fetch_assoc($result)) 
    { 
     $posts_sql = "SELECT 'posts.post_topic', 'posts.post_content', 'posts.post_date', 'posts.post_by', 
          'users.user_id', 'users.username', 'users.profile' 
       FROM 
        `posts` 
       LEFT JOIN 
        `users` 
       ON 
        posts.post_by = users.user_id 
       WHERE 
        posts.post_topic = " . mysql_real_escape_string($_GET['id']); 

     $posts_result = mysql_query($posts_sql); 

     if(!$posts_result) 
     { 
      echo '<tr><td>The posts could not be displayed, please try again later.</tr></td></table>'; 
     } 
     else 
     { 

      while($posts_row = mysql_fetch_assoc($posts_result)) 
      { 
       include("includes/results-template.php"); 

      } 
     } 

     if(!$_SESSION['signed_in']) 
     { 
      echo '<tr><td colspan=2>You must be <a href="signin.php">signed in</a> to reply. You can also <a href="signup.php">sign up</a> for an account.'; 
     } 
     else 
     { 
      //show reply box 
      echo '<tr><td colspan="2"><h2>Reply:</h2><br /> 
       <form method="post" action="reply.php?id=' . $row['topic_id'] . '"> 
        <textarea name="reply-content"></textarea><br /><br /> 
        <input type="submit" value="Submit reply" /> 
       </form></td></tr>'; 
     } 

     //finish the table 
     echo '</table>'; 
    } 
} 
} 
?> 
<?php include 'includes/overall/footer.php'; ?> 

답변

0

작은 따옴표로 열을 선택하면 안되며, 대신 역 따옴표로 열을 선택해야합니다.

$sql = "SELECT `topic_id`, `topic_subject`, `category`, `sub_category`, `posted_by`, `posted`, `view`, `reply` FROM `topics` 
WHERE topics.topic_id = '".mysql_real_escape_string($_GET['id'])."' "; 

에 조회를 변경하고 또한이 쿼리 $posts_sql을 변경

: '는 역 따옴표 사이에 다른`와 작은 따옴표가

 $posts_sql = "SELECT posts.post_topic, posts.post_content, posts.post_date, posts.post_by, users.user_id, users.username, users.profile 
      FROM 
       `posts` 
      LEFT JOIN 
       `users` 
      ON 
       posts.post_by = users.user_id 
      WHERE 
       posts.post_topic = '" . mysql_real_escape_string($_GET['id'])."' "; 

.

관련 문제