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 6 years ago.
Improve this question
I'm working on a website and I've got up to a bit now where I want text on the homepage to change, depending on whether or not the user is logged in. Before doing this, I wrapped the text in a div class, which has allowed me to configure how it looks inside a css file. By default, if the user is not logged in, the index.html should display "iBPBuyer, Amazing Deals & Prices." and when the user is logged in, it should then change that text to a simple welcome message, stating their name afterwards, but I cannot seem to get it working.
<?php
require("includes/application_top.php");
require("includes/site_header.php");
require("includes/application_bottom.php");
if($_SESSION['id']) {
echo '<div class="hero-text-box">
<h1>Welcome,<br> $_SESSION['first'].</h1>
</div>
<div class="row">
</div>';
} else {
echo '<div class="hero-text-box">
<h1>iBPBuyer,<br> Amazing Deals & Prices.</h1>
</div>
<div class="row">
</div>';
}
?>
Logged part should be:
echo '<div class="hero-text-box">
<h1>Welcome,<br>' . $_SESSION['first'] . '</h1>
</div>
<div class="row">
</div>';
So, it's just correct concatenation technique.
Simplify your code
$welcome = "iBPBuyer,<br> Amazing Deals & Prices.";
if($_SESSION['id']) {
$welcome = 'Welcome,<br> ' . $_SESSION['first'];
}
echo '<div class="hero-text-box">
<h1>' . $welcome . '</h1>
</div>
<div class="row">
</div>';
Related
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));
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 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
}
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question appears to be off-topic because it lacks sufficient information to diagnose the problem. Describe your problem in more detail or include a minimal example in the question itself.
Closed 8 years ago.
Improve this question
im not familiar with PHP, but I'd like to create in Wordpress something like:
if page id="123"
show this -> <div class"option one">my content</div>
if page id="124"
show this -> <div class"option two">my other content</div>
if page id="125"
show this -> <div class"option three">my other content 2</div>
The code will be placed in my page.php
So what is the exact php code?
for example you have page_id 123, 124 ...etc then
Do it as:
<?php if ( is_page(123) ) {
?>
<div class="option one">my content</div>
<?php } elseif( is_page(124) ) {
?>
<div class="option one">abc content</div>
<?php }
else {
echo '<div class="option one">any content</div>';
}
?>
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 9 years ago.
Improve this question
Hey I have a question that I can not seem to figure out, how can I make a $function echo a html markup like this code:
<div style="color: purple;">Hello</div>
I can not seem to get it. Here is the code I am using is not working:
$contactUs = echo <div style="color: green;">click here</div>;
How can I make my $function work?
$contactUs = '<div style="color: green;">click here</div>';
echo $contactUs;
Not really sure what you're asking about, but you can do:
$function = function() { echo '<div style="color: green;">click here</div>'; };
...
$function();
1° In php, all strings need to be surrounded by quotes:
'<div style="color: green;">click here</div>';
Then, echo is a language construct which send text to output (your screen for example);
// If you want to use a variable
$contactUs = '<div style="color: green;">click here</div>';
echo $contactUs;
// but you can use echo 'your string':
echo '<div style="color: green;">click here</div>';