I need some help..
I have a line of PHP that is echoing a url for me -
<?php foreach($day as $item) : ?>
<li style="background: url('<?php echo http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid=$item['tvdbid']?>')"><?php echo $item['show_name'] ?> </br> <?php echo $item['ep_name'] ?></li>
<?php endforeach ?>
The problem I have is that the URL here -
<li style="background: url('<?php echo http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid=$item['tvdbid']?>')">
Appears to kill the code, so I assume my syntax is wrong, if I remove the "background stuff" the code works and the other 2 variables are mapped ok, i'm now wanting to set the backgroud of each li as per the image being returned from the API call, but I can't get it working..i'm sure someone here will sort it really easily for me..
Thanks
Yes you have syntax error in your code:
Modified Example:
<li style='background: url(<?php echo 'http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid='.$item['tvdbid'];?>)'>
Alternate Solution:
<?php
$url = "http://$base:$sickport/api/$SICKAPI/?cmd=show.getbanner&tvdbid=".$item['tvdbid'];
?>
<li style='background: url(<?php echo $url; ?>)'>
Related
I know I'm probably missing something really obvious, but the background image isn't pulling through...
<div style='background-image: url(<?php echo $blogImage; ?>");'>
I've also tried:
<div <?php echo "style='background-image: url($blogImage);'";?> >
Syntax error
Use this
<div style="background-image: url('<?php echo $blogImage; ?>');">
Hope this helps
You have a missing " before the php opening tag. try to add it and check.
<div style='background-image: url("<?php echo $blogImage; ?>");'>
<?php
$name = "{{t_33}}";
$y=$name;
for($i=$y;$i<24;$i++) { ?>
<li>
<a class="<?php
if (($i>0 and $i<4) || ($i>20 and $i<24)) echo 'dark';
else if (($i>3 and $i<8)|| ($i>16 and $i<21)) echo 'light';
else if ($i>7 and $i<17) echo ''; ?>"
href="#">
<?php echo $i; ?>
</a>
<?php if($i==1) { ?>
<h4>{{day}}</h4>
<?php } ?>
</li>
<?php } ?>
The issue is that I am getting the value in $name but when I assign it in $y and try to use it in for loop the page goes blank. Please help.
I think that issue is with order of processing your code. You should know that php is interpreted on server side and javascript is procesed on client side.
Now when your angular is code running, php functions are already processed. (I'm simplyfing here ofc.)
I have created a homepage editor tool in a script I purchased. The function of this homepage editor is to allow me to create different sections and display them one on top of the other in the order they are created. Which in hopes will give me an effect of several blocks that stretch width of the screen.
All seems to work well except one piece. I input my html and php code into the field in the admin panel and it saves to the db as I wrote it. However, when I go to echo each section back to the homepage it just displays my php code as plain text and doesn't interpret it as php and do its function.
Here is code from the homepage.php that prints the results.
<?php
session_start();
require_once("inc/config.inc.php");
if (isset($_GET['ref']) && is_numeric($_GET['ref']))
{
$ref_id = (int)$_GET['ref'];
setReferal($ref_id);
header("Location: index.php");
exit();
}
/////////////// Page config ///////////////
function get_all_section($section_id='')
{
$sql="SELECT * FROM `cashbackengine_homepage` WHERE 1";
if($section_id!="")
{
$sql.=" AND section_id='".$section_id."'";
}
$sql.=" AND section_status=1";
$sql.=" ORDER BY section_order ASC";
//echo $sql;
$res=mysql_query($sql);
while($row=mysql_fetch_array($res))
{
$section_array[]=array(
'section_id' =>$row['section_id'],
'section_name' =>$row['section_name'],
'section_desc' =>$row['section_desc'],
'section_order' =>$row['section_order'],
'section_status' =>$row['section_status'],
'last_updated' =>$row['last_updated'],
);
}
return $section_array;
}
$get_all_section=get_all_section('');
/*$get_all_section2=get_all_section('2');
$get_all_section3=get_all_section('3');
$get_all_section4=get_all_section('4');
$get_all_section5=get_all_section('5');*/
for($i=0; $i<count($get_all_section);$i++)
{
//echo htmlspecialchars_decode($get_all_section[$i]['section_desc']);
//echo htmlspecialchars_decode(stripslashes(str_replace(" ","",(str_replace("<br />","\n",$get_all_section[$i]['section_desc'])))));
echo $get_all_section[$i]['section_desc'];
}
?>
I am certain the problem has to do with the echo at the end. But I am unsure how to use htmlspecialchars to make it work with php if it even will. Or if I have to put something weird in my saved section.
Here is one of my sections. Any help is greatly appreciated. Thank you.
<div style="height:260px; width:100%; background-color:#000; margin:0px; color:white;">
<div id="header">
<div id="logo"><img src="<?php echo SITE_URL; ?>images/logo.png" alt="<?php echo SITE_TITLE; ?>" title="<?php echo SITE_TITLE; ?>" border="0" /></div>
<div class="start_saving">
<div id="links">
<?php if (MULTILINGUAL == 1 && count($languages) > 0) { ?>
<div id="languages">
<?php foreach ($languages AS $language_code => $language) { ?>
<img src="<?php echo SITE_URL; ?>images/flags/<?php echo $language_code; ?>.png" alt="<?php echo $language; ?>" border="0" />
<?php } ?>
</div>
<?php } ?>
<div id="welcome">
<?php if (isLoggedIn()) { ?>
<?php echo CBE_WELCOME; ?>, <span class="member"><?php echo $_SESSION['FirstName']; ?></span><!-- | <?php echo CBE_ACCOUNT ?>--> | <?php echo CBE_BALANCE; ?>: <span class="mbalance"><?php echo GetUserBalance($_SESSION['userid']); ?></span> | <?php echo CBE_REFERRALS; ?>: <span class="referrals"><?php echo GetReferralsTotal($_SESSION['userid']); ?></span>
<?php }else{ ?>
<a class="signup" href="<?php echo SITE_URL; ?>signup.php"><?php echo CBE_SIGNUP; ?></a> <a class="login" href="<?php echo SITE_URL; ?>login.php"><?php echo CBE_LOGIN; ?></a>
<?php } ?>
</div>
</div></div>
</div>
It looks like you're getting these section contents pieces out of your database, and not from a file stored on your web server. Is that correct?
Assuming that's true, then my next question would be, who populates this data? Is this taken in any way from user input? The reason why I ask is because of my next suggestion, which may or may not be received well.
The reason why your PHP code isn't executing, is because it's being retrieved from the database and output as a string, not as code. So how do you execute code that's stored in a string, you ask? Well, the answer to that question is to use eval() on the string. But this is where you have to be really careful!!!!!!! If any part of that string could have possibly come from an untrusted source, then malicious PHP code could be executed, which could potentially give evildoers a way into your server, where they can find all the information in your database, server, etc. Make sure you know where your code is coming from before executing it!
You make a good point that it's HTML mixed with PHP. So I see two possible solutions...
This post suggests that you could do eval(' ?>'. $section .' <?php'); This makes sense, you're breaking out of PHP before you eval your string, and so requiring the included string to open its own PHP tags to write PHP code.
Another way I can think of would be to throw the contents into a temporary file, and then include() that file:
// get contents, store in $contents
$filename = tempnam(sys_get_temp_dir(), 'section');
file_put_contents($filename, $section);
include($filename);
unlink($filename);
I'm designing a web page to show some commodity
results (such Model, price, Comment) for every Commodity is a database
and I call theme to show in each Commodity (it while be shown in a div)
I wanna to set backgrounds for each div (it saved in database and every Commodity have one background-image)
please tell me whats the true syntax for this div s
for example I wrote this code:
<div class="commodities"> <style>.commodities{ background-image:<?php $Images[$i]?>} </style>
<?php
echo "Model:";
echo $Models[$i];
echo "<br><br>";
echo "Price: ";
echo $Prices[$i];
echo "<br><br>";
echo $Comments[$i];
?>
</div>
please help me to fix this part of code: { background-image:}
You have to do this:
<div class="commodities" style="background-image: url('<?php $Images[$i]?>');">
<?php
echo "Model:";
echo $Models[$i];
echo "<br><br>";
echo "Price: ";
echo $Prices[$i];
echo "<br><br>";
echo $Comments[$i];
?>
</div>
If you put < style > tags in the < body > (put it on the < head > tags) you are doing nothing ;)
Instead use style property. ;)
Apart you are forgetting to use url tag on the background-image property. ;)
You are missing two keywords, scoped and url. See e.g. http://www.w3schools.com/tags/att_style_scoped.asp and http://www.w3schools.com/cssref/pr_background-image.asp.
use inline css.
<div style="background-image: url(<?php echo $variable_name; ?>);">
or
use internal css.
<style type="text/css">
.logo {
background: #FFF url(<?php echo $variable_name; ?>);
}
</style>
I start the page with the:
$selectedMenu = $_GET['selectedMenu'];
Then I have next and previous functions
<?php if ($prev) { ?>
<a href='?AID=<?=$prev?>&selectedMenu=$selectedMenu' style='background-image:url(/images/navDivider.png); background-position:right center; background-repeat: no-repeat; padding-bottom:4px; padding-top:4px;'>back </a>
<?php } else { ?>
<a href='gallery.php?CID=<?=$CID?>&SCID=<?=$SCID?>&selectedMenu=$selectedMenu' style='background-image:url(/images/navDivider.png); background-position:right center; background-repeat: no-repeat; padding-bottom:4px; padding-top:4px;'>back </a>
<?php } ?>
<?php if ($next){ ?>
<a href='?AID=<?=$next?>&selectedMenu=$selectedMenu'> next</a>
<?php } ?>
There is a query that pulls the AID, CID, and SCID
But what happens is that the $selectedMenu won't stay after the fist page even though I am passing it in the url. Any clues why it's dropping out?
Try using a query string management class. For example: https://github.com/kenaniah/insight/blob/master/classes/querystring.php
Example usage:
<?php
$qs = new QueryString;
$qs->CID = $CID;
print "<a href='blah.php".$qs."'>Link</a>";
?>
Try this:
<?php if ($prev) { ?>
back
<?php } else { ?>
back
<?php } ?>
<?php if ($next) { ?>
next
<?php } ?>
It was probably because you had a PHP variable in there without a surrounding PHP start and end tag. Also gave you proper echo statements.
Edit: Damn, realized you already got the answer.