2013-01-06 4 views
-1

가입 나는MySQL의 오류

<?php 
//create_cat.php 
include 'connect.php'; 
include 'header.php'; 

$sql = "SELECT 
      topic_id, 
      topic_subject, 
      topic_cat 
     FROM 
      topics 
     WHERE 
      topics.topic_id = " . mysql_real_escape_string($_GET['id']); 

$result = mysql_query($sql); 
$row = mysql_fetch_assoc($result); 

echo '<a href="index.php">Nexus</a> > <a href="category.php?id=' . $row['topic_cat'] . '">Category will go here.</a> > <a href="topic.php?id=' . $row['topic_id'] . '">' . $row['topic_subject'] . '</a><br>'; 

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 
    { 

     { 
      //display post data 
      echo '<table class="topic"> 
        <tr> 
         <th colspan="2">' . $row['topic_subject'] . '</th> 
        </tr>'; 

      //fetch the posts from the database 
      $posts_sql = "SELECT 
         posts.post_topic, 
         posts.post_content, 
         posts.post_date, 
         posts.post_by, 
         posts.post_id, 
         users.user_id, 
         users.user_name, 
         users.user_title, 
        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)) 
       { 
        echo '<tr class="topic-post"> 

          <td class="user-post"><div id="user"> 
           <b>' . $posts_row['user_name'] . '</b><br/>' . $posts_row['user_title'] . '</div><br/>' . date('m-d-Y h:ia', strtotime($posts_row['post_date'])) . '</td> 
          <td class="post-content"> 
          <a name="postid=' . $posts_row['post_id'] . '"></a> 
          ' . htmlentities(stripslashes($posts_row['post_content'])) . '</td> 
          </tr>'; 
       } 
      } 

      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 id="button" type="submit" value="Submit reply" /> 
        </form></td></tr>'; 
      } 

      //finish the table 
      echo '</table>'; 
     } 
    } 
} 

include 'footer.php'; 
?> 

문제를 데 그것은

당신은 당신의 SQL 구문에 오류가 말한다 하단에 라인 (10)

에서 '게시물 LEFT posts.post_by = U ON 사용자를 가입 FROM'근처 사용할 수있는 권리 구문에 대한 MySQL 서버 버전에 해당하는 설명서를 확인 (내가) (에코 mysql_error를 추가 아래쪽). 이것은 다른 사람들이 실제로 사용하는 포럼 소프트웨어의 경우와 마찬가지로 중요합니다. 과도한 것으로 보이지만 모두가 동일한 데이터베이스에 일시적으로 연결되어 있습니다. 하나는 적극적으로 개발하는 것이고 다른 것은 실제 소프트웨어 용입니다). 당신의 SELECT 목록의 마지막 항목 다음에 쉼표있다 -

+2

코드에 연결하지 마십시오. 여기에 입력하십시오. 질문은 혼자있을 것으로 예상됩니다. – Charles

답변

3

당신은

SELECT 
     posts.post_topic, 
     posts.post_content, 
     posts.post_date, 
     posts.post_by, 
     posts.post_id, 
     users.user_id, 
     users.user_name, 
     users.user_title // << remove extra comma here 
FROM 
     posts 
LEFT JOIN 
     users 
ON 
     posts.post_by = users.user_id 
+0

고마워요! 내가 gravatiars에 users.user_email 부분을 가져간 후에 그런 일이 일어 났음에 틀림 없다. – user1640021

+0

죄송합니다. 나는 아직도 여기에서 꽤 새로운 편이다. – user1640021

0

라인 49, 제거 할 수있는 from 절 전에 여분의 쉼표가 있습니다.