using an image as a link (php) - php

can anyone tell my why this:
echo "<a href='productdetail.php?product=" . $rij['productnaam'] . "'><img src='../images/producten/monster_energy_green.png' alt='' /></a>";
does give a clickable image link, and this:
echo "<a href='productdetail.php?product=" . $rij['productnaam'] . "'><img src='" . $rij['afbeelding_klein'] . "' alt'productafbeelding' /></a>";
doesnt? (not clickable).
thanks in advance!!
php rookie..

In the first one you have a real scr it's directing to with a file extension. the second does not. If the second is supposed to be picking up a variable we would need more information

echo "<a href='productdetail.php?product=" . $rij['productnaam'] . "'><img src='" . $rij['afbeelding_klein'] . "' alt='productafbeelding' /></a>";
just add a "=" between alt and 'productafbeelding'

Try this one:
echo '<img src="' . $rij['afbeelding_klein'] . '" alt="productafbeelding" />';

Related

How to make a PHP echo into a link

I'm trying to get this so when I click the image, the image then shows in a new tab so it's able to be saved
I've tried adding the a href tags inside and around.
Code:
echo "<img src=" . random_image('css/avatars') . " />";
This is what you want:
echo '<img src="' . random_image('css/avatars') . '" />';
You should try
echo "<a target='_blank' href='".random_image('css/avatars')."'>"."<img src=" . random_image('css/avatars') . " /></a>";
I think this can help you
The problem is that you are not properly concatenating your string with what you get from random_image function.
You can try following code, here I am assuming that your random_image function returns complete path to your image
function random_image($path)
{
// returning dummmy image
return "https://images.unsplash.com/photo-1535498730771-e735b998cd64?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=623ed05afcc5a3fa1e444ffca95854dc&w=1000&q=80";
}
echo "<a href='".random_image('css/avatars')."' target='_blank'> <img src='".random_image('css/avatars')."' /></a>";

Adding php inside image src not working?

I know this has already been put out on here but I've looked and mine still won't work and I don't know why someone please give me a hand.
echo '<img src="' . Mage::helper('catalog/image')->init($_product, 'small_image')->resize(50,50); . '"/>';
Remove the semicolon you have after resize
echo '<img src="' . Mage::helper('catalog/image')->init($_product, 'small_image')->resize(50,50) . '"/>';
Try this
echo "<img src= '".Mage::helper('catalog/image')->init($_product, 'small_image')->resize(50,50)."'/>";
Please change
echo '<img src="' . Mage::helper('catalog/image')->init($_product, 'small_image')->resize(50,50); . '"/>';
this line to
echo '<img src="' . Mage::helper('catalog/image')->init($_product, 'small_image')->resize(50,50) . '"/>';
Because you had put one extra semi column ; after the resize(50,50)
Please change your code and try. Definitely work .

defining POST variable as href link, target='blank'

I am trying to edit this code to make it a link which opens ins a new tab, but wherever I insert the "target='blank'" part in the code I get a parse error, can anyone one help me out please. Thanks.
$websiteurl = "" . $_POST['websiteurl'] . "";
need to add:
target='blank'
$websiteurl = '<a target="_blank" href="' .
$_POST['websiteurl'] . '">' . $_POST['websiteurl'] . '</a>';
You missed _.
put target="_blank"
Mine is like this:
$output .= "<p class='fb-page-name'><a href='". $app['link'] ."' title='". $app['name'] ."'>". $app['name'] ."</a></p>\n";
I had to use target='_blank' instead of target="_blank".
I'm just saying because maybe someone is struggling with it as I was.
$websiteurl = '' . $_POST['websiteurl'] . '';

How to add a variable to this?

I am using the following snippet. How do I add q=$k in the <a href url>?
<?php
echo '<a id=d href="'.$_SERVER['PHP_SELF'].'?pg='.($s+10).'">Next</a>';
?>
<?php
echo '<a id=d href="'.$_SERVER['PHP_SELF'].'?pg='.($s+10).'&q='.$k.'">Next</a>';
?>
Something like that?
echo '<a id=d href="' . $_SERVER['PHP_SELF'] . '?pg=' . ($s+10) . '&q=' . $k . '">Next</a>';
You can do this:
echo "<a id='d' href='" . html_entities("$_SERVER[PHP_SELF]?pg="
. urlencode($s + 10) . "&q=" . urlencode($k)) . "'>Next</a>";
I added suitable escaping for the URL parameter and HTML output: URL encoding for the URL GET parameters, and HTML entity replacement for the entire URL string.

correct way to echo a link with a onclick javascript function

my question is how I can echo this the right way
because the variable in the onclick function gives out a undefined error
$openchat="<a href='javascript:void(0)' onClick='return chatWith(" . $livenaam .")'>" . $livenaam . "</a><br>";
echo $openchat;
I want to use it in a loop to get a list off users online for the chat
Thanks, Richard
Looks like you are missing some quotes:
$openchat="<a href='javascript:void(0)' onClick='return chatWith(\"" . $livenaam ."\")'>" . $livenaam . "</a><br>";
or for increased security:
$openchat="<a href='javascript:void(0)' onClick='return chatWith(\"" . htmlspecialchars($livenaam,ENT_QUOTES) ."\")'>" . htmlspecialchars($livenaam,ENT_QUOTES) . "</a><br>";
Try this:
'' . htmlspecialchars($livenaam) . '<br>'
If json_encode is not available, try this:
'' . htmlspecialchars($livenaam) . '<br>'

Categories