Why is this code not displaying my photo on the page? - php

if my query is working fine by fetch the data from the database.
The variables are working fine as well. The name for the image in the database is stored in the post_banner column. please note that the original file is stored in the server folder only the image name is sent to the database.
if the variable is like this:
$featured_post_image = $post['post_banner'];
<?php echo "<img class='img_ft' src='content/newsimages/'".$featured_post_image."' alt='$featured_post_image'> "; ?>
This code is not display the image from the sever folder. What is wrong?

Maybe it's just a problem with single and double quotes.
your line
<?php echo "<img class='img_ft' src='content/newsimages/'".$featured_post_image."' alt='$featured_post_image'> "; ?>
Should be
<?php echo "<img class='img_ft' src='content/newsimages/".$featured_post_image."' alt='$featured_post_image'> "; ?>
Please note the absence of a quote after /newsimages/

Related

Why can't I echo using an img tag?

I'm trying to echo my uploaded image from database using img tag and php variable. I've tried this code but it does not display the image at all,
but the other code works fine, the original of the path of the image is https://localhost/admin/uploads
here is my query for file upload and print screen of my code and output,move to upload file,fetching image,output
if($query_run)
{
move_uploaded_file($_FILES["emp_image"]["tmp_name"],'/uploads/'.$_FILES["emp_image"]["name"]);
$_SESSION['success'] = "Employee Record Added";
header('Location: create.php');
}
here is my code to fetch the image
<?php
while($row = mysqli_fetch_assoc($query_run))
{
?>
<td><?php echo $row['id']?></td>
<td><?php echo '<img src="uploads/'.$row["emp_image"].'" width="100px;"
height="100px;" alt="Image"/>'?></td>
<td><?php echo $row['s_name']?></td>
Your code looks good. You should checkout something...
Is output of 'uploads/'.$row["emp_image"] actual path name of image file?
Remove ; in width="100px;" height="100px;"
Check query and check in emp_image image path is correct or not.
Better use like this.
Note: First you have to print the $row["emp_image"] then ensure the path is correct.
<td><img src="uploads/<?php echo $row["emp_image"]; ?>" width="100px;"
height="100px;" alt="Image"/></td>
I am confusing with the single quotes and double quotes between your code. so better use this way.

php display <img src /> in Joomla based on link in Database column

I am trying to display an image linked to a user that is logged in based on a Joomla site.
The PHP code I am using is as follows:
<?php
$user = JFactory::getUser();
$username = $user->username;
echo '<img src="$user->picture" />'
;
?>
During my testing and troubleshooting, I tested without the image source tag and I received the call back from my database table labeled Images/LOGO.jpg which displayed as a string on my front end.
when I use the Image source again and replace $user->picture with the same string from the DB column, the image returns 100%.
By leaving the code as per above the page loads successfully but no image is returned.
Thanks,
The Bug is quite obvious....echo '<img src="$user->picture" />'Did you notice anything unusual in the Snippet above?
Here is a Hint: Try this: <?php $var="test"; echo '$var'; ?> What did you get?
Sure you got it all back as is: VERBATIM - $var instead of the expected test. So here's the Catch: Any variable within Single Quotes in PHP would NOT expand/evaluate to a Value...You'd just get the Variable back: Verbatim
Rather do it like so:
<?php
$user = JFactory::getUser();
$username = $user->username;
// NOTICE THE DOUBLE QUOTES SURROUNDING THE "<img... />" TAG
// THOUGH NOT SO IMPORTANT, BUT NOTICE ALSO THE BRACES AROUND
// {$user->picture}
echo "<img src='{$user->picture}' />";
By the way; in Joomla, you could get the User-Avatar like so:
<?php
// USE jimport TO PULL IN THE PROFILE PICTURE CLASS
jimport('profilepicture.profilepicture');
// GET THE USER OBJECT LIKE YOU ALREADY DID
$user = JFactory::getUser();
// CREATE A NEW INSTANCE OF THE ProfilePicture CLASS PASSING IT THE USER ID
$userPix = new ProfilePicture($user->get('id'));
// ECHO OUT THE ENTIRE HTML FOR THE USER PROFILE PICTURE
echo $userPix->toHTML();
Cheers & Good-Luck, Mate! 💪☝️✌️
single quote does not print the var value, change it to
"<img src=\"$user->picture\" />"

How do you write HTML in a MySQL database field and echo it with PHP?

I'm stuck trying to echo my product descriptions correctly for my eCommerce store.
Is it possible to write formatted HTML (i.e. with elements and tags... to youtube links, etc) as text in a MySQL description field and then echo it with PHP correctly formatted?
At the moment I am using...
<?php
echo "<p>".Helper::encodeHTML($product['description'])."</p>";
?>
...but as I say it doesn't output as formatted.
Thanks for the help! :)
Edit; Fixed for the moment ('less anything changes) with...
echo html_entity_decode($var['string']);
i.e.
echo html_entity_decode($product['description2']);
http://uk1.php.net/manual/en/function.html-entity-decode.php
How about removing the p tag and echo it as is?
<?php
echo Helper::encodeHTML($product['description']);
?>
or echo it with htmlentities() like this:
<?php
echo htmlentities($product['description']);
?>
or echo it directly like this:
<?php
echo $product['description'];
?>

echo images using php

what am i trying to do is echo an image using php,
my code is really simple..
i have stored the path of the image in mysql db..
the path of the image is: ../users/profiles/23/images/dps/1409947526.jpg
now i am using the following code to output this picture:
mysql_connect("localhost", "root", "") or die("error!");
mysql_select_db("xone");
$query = mysql_query("SELECT * FROM userdpcover WHERE id='23'");
$result = mysql_fetch_array($query);
$dir = $result['dp_address'];
$dp_name = $result['dp_name'];
$dp = $dir.$dp_name;
echo $dp;
echo "<img src='$dp' />";
but when i run this code, all i get is an broken image!
thanks in advance!
Have you tried this?
echo "<img src='".$dp."' />";
Please try this and please check your image path url correct....
<?php
//here your code
?>//close php tag and try this ...
<img src="<?php echo $dp; ?>"/>
<?php
//your code here
?>
View the source of the output HTML. This will tell you the image path. You probably need to modify it.
Also, remember to set your base URL in a PHP config file to avoid repeating URL paths.

Links from Array

I kind of have a problem.
Maybe I'm doing the hardest way, I do not really know, if you could I'll appreciate for your help.
I upload photo to FTP and URL was upload to mysql in this format (http:///claim/img/box.png, http:///claim/img/box.png) with specific ID
-----------------------------------
ID - URL
1 - http://*/claim/img/box.png, http://*/claim/img/box.png
-----------------------------------
And later I grab this data, and to generated form by ID.
I used explode to divide URL. And with FOR loop, I would display it perefctly, But here is the glitch. Because there is need to make export this form as a doc file and send email with this generated form. I can't end echo.
Because when I do only first part is send, but not images from array.
For example:
$email = "ID 1<br>(Its the start of the form)";
$photos = explode(',', $claim['photos_url']); $arrlength = count($photos);
for($x=0;$x<$arrlength;$x++) {
echo "<img src=".$photos[$x]."><br>"; }
echo "The end of form";
I similar cases I simply use echo "the start of text".$date."the end";
But now, I have no idea how to do it.
Thank you for your help in advance.
your code looks so incomplete , but i think you have an array some how that includes image urls
and you want to echo each one of them :
$images = array("http://127.0.0.1/img/1.jpg","http://127.0.0.1/img/2.jpg","http://127.0.0.1/img/3.jpg");
foreach($images as $image)
{
echo "<img src='".$image."' />";
}
im not sure if i understand u correctly but hope it helps...

Categories