2

I have a PHP script to echo the contents of a Mysql table. I'm using it as a small CMS for a static page.

What I want to know is how can I go about displaying an Image in my PHP script. I have a form that submits the Date, Title, Message, and Image.

I'm using the Image field to insert the URL of an image. Whats the correct way of displaying the image on a page.

Below is my code:

<?php $con = mysql_connect("localhost","name","password"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("databaseName", $con); $result = mysql_query("SELECT * FROM Blog"); while($row = mysql_fetch_array($result)) { echo $row['Date']; echo "<br />"; echo $row['Title']; echo "<br />"; echo $row['Message']; echo "<br />"; echo $row['Image']; echo "<br />"; echo "<br />"; echo "<br />"; } mysql_close($con); ?> 

This is the outcome:

17th Feb
Title
Here is my Message
http‍://vickybeeching.com/blog/wp-content/uploads/2011/09/canthearyou.jpeg


18th Feb
Title
Here is my Message
http‍://vickybeeching.com/blog/wp-content/uploads/2011/09/canthearyou.jpeg

but I want the page to display the image not the URL. I'm guessing just using the <img></img> tags, but I'm not sure where in the PHP.

1

3 Answers 3

2

You can write code in image tag instead of echo directly.

Try this code.

echo "<img src='".$row['Image']."'/>"; 
Sign up to request clarification or add additional context in comments.

Comments

2

Try this code, but give image folder path perfectly

<?php $imagepath = "../uploads/"; echo "<img src='".$imagepath.$row['Image']. "' alt='' height='200' width='200' /> "; ?> 

According to need , you can change height and width of the image. but clarity differs.

Thanks

Comments

0
 echo $row['Image']; 

replace like this

 echo '<img src="'.$row['Image'].'" alt="" />'; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.