Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 9 months ago.
Improve this question
I have a longblob field in mysql database that stores a binary value for a image that i uploaded through my webpage.
I am trying to get the image using
<?php while( $record = mysqli_fetch_assoc( $result ) ): ?>
<div>
<?php echo '<img src="data:image/jpeg;base64,'.base64_encode($record['image']).'"height="300" width="300"/>'?>
<br/>
<?php echo "Title:".htmlentities( $record['title'] ); ?>
<br/>
<?php echo "Genre:".htmlentities($record['genre']); ?>
<br/>
<?php echo "Author:".htmlentities( $record['author'] ); ?>
<br/>
Edit</i>
<br/>
<a href="books.php?delete=<?php echo $record['id']; ?>"
onclick="javascript:confirm('Are you sure you want to delete this project?');" style="color:#1217b3">Delete</i></a>
</div>
<?php endwhile; ?>
and img tag looks like this in html
<img src="data:image/jpeg;base64,MlN0YXRlLmpwZw==" height="300" width="300">
You have base64 encoded the image file name not the file contents
MlN0YXRlLmpwZw==
actually outputs:
2State.jpg
When storing it in the database you need to do
$imageContent = base64_encode(file_get_contents($file));
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
If <?php echo $jsonObj->data->image; ?> has a value, like 1234.jpg I want to show this:
<img src="https://www.example.com/img/<?php echo $jsonObj->data->image; ?>" />
If <?php echo $jsonObj->data->image; ?> has no value, then <img src="https://www.example.com/img/<?php echo $jsonObj->data->image; ?>" /> should remain hidden.
Any help please?
Use php if-else statement for that.
<?php
if(!empty($jsonObj->data->image)) {
?>
<img src="https://www.example.com/img/<?php echo $jsonObj->data->image; ?>" />
<?php
}
?>
You can add else part and do whatever you want.
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
Im new to php and i am trying study how to design web page, the code is not mine. My problem is , i have some clickable done using a table for that i have an array
$buttons=array('Home'=>'home.php',
'Contact'=>'contact.php',
'Services'=>'service.php',
'Site map'=> 'map.php');
and there is a function
function DisplayMenu($buttons)
{
echo "<table width='100%' bgcolor
='white' cellpadding='4'
cellspacing='4'\n";
echo "<tr>\n";
$width =100/count($buttons);
while (list($name, $url)=each ($buttons))
{
$this-> DisplayButton($width, $name,
$url);
}
echo "</tr>\n";
echo "</table>\n";
}
and for displaying the button there is also a function
function DisplayButton($width, $name, $url)
{
echo " <td width='$width%'>
<a herf ='".$url."'>
<img src= 'ab.jpg' alt='$name'
border='0'>
</a> <a herf='".$url."'><span
class ='menu'>
".$name."</span></a></td>";
}
My problem is when i click for example the home button its not taking me to the home.php page , can someone help me ?
Just a typo (herf to href)
function DisplayButton($width, $name, $url)
{
echo "
<td width='{$width}%'>
<a href='{$url}'>
<img src='ab.jpg' alt='{$name}' border='0'>
</a>
<a href='{$url}'>
<span class='menu'>{$name}</span>
</a>
</td>
";
}
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
<h1 class="site-title">
<a href="<?php echo esc_url( home_url( '/' ) ); ?>"
rel="home"><?php bloginfo( 'name' ); ?>
</a>
</h1>
if (is_category('Ponies')) { ?>
// overlay a pretty rainbow on the logo for the ponies category
<img id="rainbow"
src='<?php bloiginfo('template_directory');?>/img/rainbow.png"
alt="OMG! Ponies! " />
<?php } ?>
I'm having trouble matching the PHP tags. The comment for the code says "Now any time the category of the content is Ponies, your header also includes the rainbow.png." But it's clear how that is happening. The actual code is on p245 of WordPress Design and Developement by Williams. Thanks for putting another pair of eyes on it.
"If" is not inside <?php ... ?>. Must be:
<?php if (is_category('Ponies')) { ?>
I prefer to use <?php if (condition): ?> when there's HTML in-between.
But anyhow...
1) The if() statement needs to be inside php tags.
2) You don't need echo to retrieve the bloginfo.
bloginfo() documentation
3) You've misspelled bloginfo at the bottom...
My code:
<h1 class="site-title">
<a href="<?php echo esc_url(home_url('/')); ?>" rel="home">
<?php $bloginfo('name'); ?>
</a>
</h1>
<?php if (is_category('Ponies')) : ?>
<img id="rainbow"
src="<?php get_bloginfo('template_directory') . '/img/rainbow.png'; ?>"
alt="OMG! Ponies!" />
<?php endif; ?>
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 7 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Improve this question
<?php
include 'inc/connect.php';
if ($_GET['id'] )
{
$p_id = $_GET["id"];
$query = "SELECT * FROM products WHERE p_id= '$p_id'";
//var_dump($query);
$resu = mysqli_query($con, $query);
while($rs = mysqli_fetch_assoc($resu))
{
?> <img src="<?php echo $p_id['p_image']; ?>" alt="" /> <?php
//var_dump($query);
}
}
?>
this is my code and this is showing me error on my browser what can i do..?
image cant load
Replace this
<img src="<?php echo $rs['p_image']; ?>" alt="" />
to
<img src="<?php echo $p_id['p_image']; ?>" alt="" />
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I need the data to have a different style if the sold = 0 in the mysql table
and when i use the code below the website shows a blank white page
(?=$vehicle-> this is the vehicle reference
and sold is the column withing the sql table
<?php
if (?=$vehicle->sold?!= 1)
{
<div class="foo">
<div class="fboverlay"></div>
<a>
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
</a>
</div>
}
else {
<img src="/media.php?productId=<?=$vehicle->vehicle_id?>&file=<?=$vehicle->main_image?>" />
}
?>
You need to learn the PHP from the basics. Learn about operators, PHP and HTML secion, etc..
Anyway, i fixed your code. The condition is if $vehicle->sold is not equal to 1. But i think, (in your OP you mentioned it should be 0) you want this: $vehicle->sold == 0
//Use sytnax like this. See php opeartors.
if ($vehicle->sold != 1) {
?> <!-- Close the php -->
<div class = "foo">
<div class = "fboverlay"></div>
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
</div>
<?php
//Open the php again
} else {
?> <!-- close the php -->
<img src = "/media.php?productId=<?= $vehicle->vehicle_id ?>&file=<?= $vehicle->main_image ?>" />
<?php //Open again
}