0

I am currently creating a CMS.

Currently I have.
* Saved my images in mysql as app_image
* Saved the images as a URL to where the images are located

But creating MY INDEX PAGE only displays my link as a broken URL.

my code for this page:

<?php

include_once('include/connection.php');
include_once('include/article.php');

$article = new article;
$articles = $article->fetch_all();

?>

<html>

<head>
<title>testing</title>
<link rel="stylesheet" href="style.css" />
</head>

<body>
<div class="container">
<a href="index.php" id="logo">CMS</a>

<ol>
    <?php foreach ($articles as $article) { ?>


         <li>
<a href="article.php?id=<?php echo $article['app_id']; ?>">
<img src="<?php echo $article['app_image']; ?>" height"100" width"100">
          <?php echo $article['app_title']; ?>

          </a> - 

          <small>
           Posted: <?php echo date('l jS', $article['article_timestamp'] ); ?>
          </small></li>


    <?php } ?>
</ol>
<br><small><a href="admin">admin</small></a>
</div>
</body>

</html>

Can anyone see how I have gone wrong?

Thanks.

5
  • 2
    Your src is coming through empty. Is app_image the right name for the column in your database? Is it being populated correctly when you save it? Commented Jul 5, 2013 at 15:21
  • Why do you don't use a mysql_fetch_array? Commented Jul 5, 2013 at 15:22
  • perfect. they where saved as app_img after i double checked. thank you for your help. My issue now. if you view my page again you will see my problem. Commented Jul 5, 2013 at 15:24
  • 3
    @user2407146 - your height and width tags aren't correctly formatted - you're missing the =. But you should be re-sizing images to create thumbnails, rather than using height and width tags to shrink them. Commented Jul 5, 2013 at 15:26
  • i missed the = . I should know that. That will teach me for jumping in to this quickly. thank you for your help Commented Jul 5, 2013 at 15:27

2 Answers 2

1

OK, I have done simalar thing and it is working just fine.

The code looks similar, and looks fine by me, now, maybe the link indeed is broken (maybe you didn't input the right upload link in DB)

I would go step by step and check that link (check if it is the right link). (with /path/name.ext)

If it is some help here is my case:

I put in DB post_id,post_title,post_contents, post_link

than i get that info with:

$query = $db->prepare ("SELECT bla bla FROM bla bla ORDER BY id DESC")
$query->execute();
$query->bind_result(everything that is selected seperated with ",");

(including $link)

<?php
while($query->fetch()):

?>  

<a href="single-post.html" title="">
<img src="../images/<?php echo $link; ?>">
</a>    

<?php
}
?> 

NOW, the trick I did (to avoid problem is that i put inside DB only the name of file, the upload path is stored directly in HTML ("../images/")

Your code looks similar, and I think it should work, I think the problem is with link.

Sign up to request clarification or add additional context in comments.

Comments

0

Var dump can come to the rescue here. Try this to see what the array key values should be set to for each of the elements in $article.

<?php foreach ($articles as $article) { ?>

echo '<pre>';   //just makes it a bit easier to read          
var_dump($article); exit;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.