php
  • html-table
  • echo
  • 2013-02-09 25 views 0 likes 
    0

    我正在試圖回顯一張信息表,特別是帖子。表格內容是否在表格之外?

    <?php 
    echo " 
    <div class='forum_banner'> 
        <div style='float:left;'> 
         <a href='?action=forum'>Forum</a> 
         > 
         <a href='?action=forum#".fetch_info(fetch_info(fetch_info($_GET['id'], 'board_id', 'topic'), 'category_id', 'board'), 'name', 'category')."'>".fetch_info(fetch_info(fetch_info($_GET['id'], 'board_id', 'topic'), 'category_id', 'board'), 'name', 'category')."</a> 
         > 
         <a href='?action=board&id=".fetch_info($_GET['id'], 'board_id', 'topic')."'>".fetch_info(fetch_info($_GET['id'], 'board_id', 'topic'), 'name', 'board')."</a> 
         > 
         <a href='?action=topic&id=".$_GET['id']."'>".fetch_info($_GET['id'], 'name', 'topic')."</a> 
        </div>"; 
        if (isset($_SESSION['id'])) 
        { 
         echo " 
         <div style='float:right;'> 
          <form method='post' action='?action=create&type=reply&id=".$_GET['id']."'> 
           <input type='submit' value='Reply'/> 
          </form> 
         </div>"; 
        } 
        echo " 
    </div>"; 
    
    
    echo " 
    <div class='content'> 
        <table class='forum_table'>"; 
         $query = mysql_query("SELECT * FROM post WHERE topic_id='".$_GET['id']."' ORDER BY time ASC") or die(mysql_error()); 
    
         echo " 
         <tr> 
          <td class='table_header' colspan='2'> 
           <b>".fetch_info($_GET['id'], 'name', 'topic')."</b> 
          </td> 
         </tr>"; 
         while($query_fetch = mysql_fetch_assoc($query)) 
         { 
          echo " 
          <tr> 
           <td class='forum_table_cell_post' width='25%'> 
            <ul class='post_info'> 
             <li><b><a href='?action=user&id=".$query_fetch['creator']."'>".fetch_info($query_fetch['creator'], 'name', 'user')."</a></b></li> 
             <li>".fetch_info($query_fetch['creator'], 'rank', 'user')."</li> 
             <li style='max-width:128px; max-height:128px; overflow:hidden;'><img src='".fetch_info($query_fetch['creator'], 'avatar', 'user')."' /></li> 
             <li>Posts: ".count_post($query_fetch['creator'])."</li> 
             <li>Reputation: ".(fetch_info($query_fetch['creator'], 'reputation', 'user')>0 ? ('<font color="#007D00">+'.fetch_info($query_fetch['creator'], 'reputation', 'user').'</font>') : (fetch_info($query_fetch['creator'], 'reputation', 'user')<0 ? ('<font color="#7D0000">'.fetch_info($query_fetch['creator'], 'reputation', 'user').'</font>') : ('<font color="#000000">'.fetch_info($query_fetch['creator'], 'reputation', 'user').'</font>')))."</li> 
            </ul> 
           </td> 
           <td class='forum_table_cell_post' width='75%'> 
            <ul class='post_info'> 
             <li><i>".convert_date($query_fetch['time']) + ($query_fetch['edit']=='0000-00-00 00:00:00' ? '' : (', last edit: '.convert_date($query_fetch['edit'])))."</i></li> 
             <div class='spacer'></div> 
             <li>".$query_fetch['body']."</li> 
             ".(fetch_info($query_fetch['creator'], 'signature', 'user') ? '<div class=\'spacer\'></div>' : '')." 
             <li>".fetch_info($query_fetch['creator'], 'signature', 'user')."</li> 
            </ul> 
           </td> 
          </tr> 
          "; 
         } 
         echo " 
        </table> 
    </div>"; 
    ?> 
    

    這是我結束了(HTML輸出):在這樣的index.php文件

    <div class='forum_banner'> 
        <div style='float:left;'> 
         <a href='?action=forum'>Forum</a> 
         > 
         <a href='?action=forum#General'>General</a> 
         > 
         <a href='?action=board&id=1'>General discussion</a> 
         > 
         <a href='?action=topic&id=1'>First topic</a> 
        </div> 
         <div style='float:right;'> 
          <form method='post' action='?action=create&type=reply&id=1'> 
           <input type='submit' value='Reply'/> 
          </form> 
         </div> 
    </div> 
    <div class='content'> 
        <table class='forum_table'> 
         <tr> 
          <td class='table_header' colspan='2'> 
           <b>First topic</b> 
          </td> 
         </tr>0</i></li> 
             <div class='spacer'></div> 
             <li>Nice first post!</li> 
             <div class='spacer'></div> 
             <li>"Non incautus futuri"</li> 
            </ul> 
           </td> 
          </tr> 
          0</i></li> 
             <div class='spacer'></div> 
             <li>This is the first topic ever made! This is the first topic ever made! This is the first topic ever made!</li> 
             <div class='spacer'></div> 
             <li>"Non incautus futuri"</li> 
            </ul> 
           </td> 
          </tr> 
    
        </table> 
    </div> 
    

    php文件是 「include'd」:「包括 'topic.php' 「並且需要從我的數據庫中回顯出一張數據表。這是爲什麼發生? 另外,這裏是我的樣式表:

    body {margin:0; padding:0; width:100%; background-color:#F0F2F3; font-family: 'Calibri', sans-serif; font-size:16px; background-image:url(img/pattern.png); background-repeat:repeat;} 
    
    p {margin:0; padding:0 0 5px 0;} 
    a:link,a:visited {color:#003399; text-decoration:none;} 
    a:hover,a:active,a:focus {color:#FF9933;} 
    input[type='textbox'],input[type='password'] {margin:0; padding:2px; height:16px; border:1px solid #CCCCCC; background-color:#FFFFFF; color:#000000;} 
    input[type='submit'] {cursor:pointer; margin:0; height: 22px; padding:2px 6px; border:1px solid #CCCCCC; background-color:#FFFFFF; color:#000000; 
    -webkit-transition: background 0.4s linear, color 0.4s linear; 
    -moz-transition: background 0.4s linear, color 0.4s linear;} 
    input[type='submit']:hover,input[type='submit']:focus {background-color:#99CCCC; color:#FFFFFF; 
    -webkit-transition: background 0.4s linear, color 0.4s linear; 
    -moz-transition: background 0.4s linear, color 0.4s linear;} 
    img {margin:0; padding:0; border:none;} 
    
    .page_wrapper {margin:0 auto; padding:0; width:900px;} 
    
    #header_area {margin:0; padding:0; width:100%;} 
    #header_box {margin:0; padding:0; width:900px;} 
    #header {float:left; margin:30px auto; padding:0;} 
    
    #user_panel {float:right; margin:26px auto; height:40px;} 
    
    #menu {margin:0; padding:0; list-style-type:none; width:100%; border:1px solid #CCCCCC; border-bottom:none; background-color:#FFFFFF; overflow:hidden;} 
    #menu li {margin:0; padding:0;} 
    #menu a:link,#menu a:visited {float:left; margin:0; border-right:1px solid #CCCCCC; padding:10px 25px; color:#000000; background-color:#FFFFFF; text-decoration:none; font-weight:bold; 
    -webkit-transition: background 0.4s linear, color 0.4s linear; 
    -moz-transition: background 0.4s linear, color 0.4s linear;} 
    #menu a:hover,#menu a:active,#menu a:focus {background-color:#99CCCC; color:#FFFFFF; 
    -webkit-transition: background 0.4s linear, color 0.4s linear; 
    -moz-transition: background 0.4s linear, color 0.4s linear;} 
    
    #content_area {margin:0; padding:0; width:100%;} 
    #content_box {margin:0; padding:0; width:900px; border:1px solid #CCCCCC; background-color:#FFFFFF; overflow:hidden;} 
    #home_sidebar {margin:0; padding:0; width:30%; float:left;} 
    #home_content {margin:0; padding:0; width:70%; float:right;} 
    .content {height:2000px; margin:10px; padding:0; overflow:hidden;} 
    
    .small_box {margin:0 150px; padding:0; border:1px solid #CCCCCC;} 
    
    .forum_table {margin:0; padding:0; border:none; width:100%;} 
    .forum_table_cell {margin:0; padding:0px 10px; background-color:#F0F2F3; height:60px;} 
    .forum_table_cell_post {margin:0; padding:10px; background-color:#F0F2F3; vertical-align:text-top;} 
    .table_header {padding:0 10px; margin:0; height:30px; font-size:18px; background-color:#FF9933;} 
    
    .spacer {margin:5px 0; padding:0; border-top:1px solid #CCCCCC;} 
    
    .forum_banner {margin: 10px 10px 0 10px; overflow:hidden; height:22px;} 
    
    .post_info {list-style-type:none; padding:0; margin:0;} 
    .post_info li {margin:2px 0 0 0; padding:0; vertical-align:text-top;} 
    
    +0

    這似乎並不是您發佈的php生成的html。例如,在你的php中沒有''元素。您應該發佈真實的html源代碼,而不是螢火蟲或開發人員工具向您展示的內容。那究竟是什麼問題? – jeroen 2013-02-09 13:49:47

    +0

    Woops,我無意中從Chrome的「檢查元素」中抓住了HTML,我用正確的代碼更新了帖子! – user1768788 2013-02-09 13:53:20

    回答

    1

    的HTML看起來像一個爛攤子。

    你應該做的第一件事情是要確保你生成有效的HTML:

    • 不要放在<div>元素的<ul>直接兒童;
    • 對輸出到html的所有變量使用htmlspecialchars以確保這些值不會破壞html。
    • 使用&gt;代替>

    此外,您的查詢有SQL注入漏洞。您應該使用預處理語句和綁定變量切換到PDO(或mysqli),以避免這種情況,或者至少將$_GET變量設置爲int(如果它是整數),如果它是字符串,則使用mysql_real_escape_string

    相關問題