dongraa1986 2014-06-07 07:46
浏览 16

PHP链接无法正常工作 - 找不到错误

I built a CMS system using CKEditor and KCFinder that store information od a databse via textarea/php. So far so good!

The issue comes to when I want to store and display images that link to themselves. The way I am storing images is exactly the same: There is a textarea where I insert an image via KCFinder/CKEditor. The image is uploaded to the server and the path stored at the database. Later I try to pick up that path from the database to display the image (that part also works) and because I want the image to link to itself, I try to use the same method to insert the url on the link. Problem? The link is missing.

Can anyone point me the error and suggest any solution? I would be so thankful!

Code:

<?php
    $sql = "SELECT * FROM php_maskiner ORDER BY timestamp DESC";

    $result = mysql_query($sql) or print ('<div class="alert alert-standard fade in">
        <a class="close" data-dismiss="alert" href="#">&times;</a>
        <strong>Can't read the database!</strong>
        </div>' . $sql . "<br />" . mysql_error());

            while($row = mysql_fetch_array($result)) {
                $title = stripslashes($row['title']);
                $entry = stripslashes($row['entry']);
                $images = html_entity_decode($row['images']);
                $img_url = $row['images'];
                $img_pack = '<div class="mask3 span3">
            <a rel="prettyPhoto" href="' . $img_url . '">' . $images . '</a>
            </div>';

?>

                <article class="span12 post"> 
                    <?php echo $img_pack; ?>
                    <div class="inside">
                      <div class="span8 entry-content">
                        <div class="span12">
                            <h2><?php echo $title; ?></h2>
                            <p><?php echo $entry; ?></p>
                        </div>
                      </div>
                    </div>
                </article>
    <?php
}
?>

UPDATE:

I think that this might be a problem caused by CKEditor. In the database the image path is store as: . This is in my understanding what is being outputted. How do I do to output only "/nysida/admin/kcfinder/upload/images/1307594_10243178.jpg"?

  • 写回答

1条回答 默认 最新

  • duanji9378 2014-06-07 08:11
    关注

    Your first mistake is still using the mysql_ extensions to access your databases. You must use PDO (if available):

    Example (for mysql):

    try {
        $DBH = new PDO('mysql:host=localhost;dbname=yourdb;charset=utf8', 'user', 'password');
        $DBH->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    
        $STH = $DBH->prepare('SELECT * FROM php_maskiner ORDER BY timestamp DESC');
        $STH->execute();
    
        $STH->setFetchMode(PDO::FETCH_OBJ);
    
        while($row = $STH->fetch()) {
            $title = $row->title;
            $entry = $row->entry;
            $images = $row->images;
            $img_url = $row->images;
            $img_pack = 
                '<div class="mask3 span3">
                    <a rel="prettyPhoto" href="'.$img_url.'"><img src="'.$images.'"></a>
                 </div>';
        }
    
        $DBH = null;
    } catch (PDOException $e) {
        echo '<div class="alert alert-standard fade in">
            <a class="close" data-dismiss="alert" href="#">&times;</a>
            <strong>Can\'t read the database!</strong>
            </div><br />'.$e;
    }
    

    And later in your code:

    <?php echo 
        '<article class="span12 post"> 
            '.$img_pack.'
            <div class="inside">
                <div class="span8 entry-content">
                    <div class="span12">
                        <h2>'.$title.'</h2>
                        <p>'.$entry.'</p>
                    </div>
                </div>
            </div>
        </article>';
    ?>
    

    And regarding the original question: make sure $img_url is not null.

    评论

报告相同问题?

悬赏问题

  • ¥15 AT89C51控制8位八段数码管显示时钟。
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口