I want to put this line into echo :
<a title=\"Details\" href=\"produit.php?Id_Produit=".$row["id_produit"]."\"><img src=\"photos_produits/".$row["image_url"]."\" /></a>
How can I do this please, I have problem with quotes !
Thanks in advance.
Try this, it might work
echo "<a title='Details' href='produit.php?Id_Produit=" .$row["id_produit"]. "'"><img src='photos_produits".$row["image_url"]. "'/></a>"
Use the easiest, heredoc
$str = <<<ANCHOR
<a title="Details" href="produit.php?Id_Produit={$row["id_produit"]}"><img src="photos_produits/{$row["image_url"]}"></a>
ANCHOR; // make sure there is no extra spaces at the start of this line
echo $str;
Related
my echo shows unexpected T_VARIABLE and i dont know how to correctly echo my href please help me
echo 'Edit'
please help me im a beginner
Replace
'Edit'
with
'Edit'
You started concatenation from the wrong place
You have incorrect use of string concatenation. Also, better use double quotes when forming the link so that you wouldn't need separate concatenation for PHP variables.
<?php
echo "<a href='/edit_account.php?id=$val[id]' class='btn btn-xs btn-info'>Edit</a>";
I believe the code should look something like this
<a href="<?php echo $your_url_variable?>" > your anchor text here </a>
or
echo '<a href="'.$your_url_variable.'">';
depending on where you want to insert the url
When I do the following line with $gamename=Cactus Canyon
echo <a href=submitascore.php?gamename=$gamename>$gamename</a><br/>;
The result is this:
http://submitascore.php?gamename=Cactus
Such that the word ' Canyon' is lost.
I'm guessing it has something to do with single and/or double quotes, but I've not been able to put together the right combination. Can you help?
Thank you!
Oh just add double quotes? This works fine.
$gamename = "Cactus";
echo "<a href=submitascore.php?gamename=$gamename>$gamename</a><br/>";
Change this:
echo <a href=submitascore.php?gamename=$gamename>$gamename</a><br/>;
To this:
echo "$gamename<br/>";
That did the trick! Thank you
I have been using this code for deleting data from database. What i wan is whenever a user clicks an image link to delete data from the confirm function prompts up and ask for action, i am getting error in this code.
$delurl = "delete_dish.php?dish_id=".$row['id'];
$img = "<img src = 'images/delete.png'>";
echo "<a href=".$delurl.";
echo "onclick='return confirm('Are you sure you want to delete.')'>".$img."</a>";
Maybe the error is in double quotes or single quotes, Any help
Thanks in advance
change
echo "<a href=".$delurl.";
to
echo "<a href=\"".$delurl."\" ";
$delurl = "delete_dish.php?dish_id=".$row['id'];
$img = "<img src = 'images/delete.png'>";
$confirm_box <<<CONFIRM
<a href="$delurl"
onclick="return confirm('Are you sure you want to delete?')">$img</a>
CONFIRM;
// then elsewhere ...
echo $confirm_box
Always tend towards using the HEREDOC syntax to construct HTML/JS output, it will save you a lot of heartache. Just watch out for the major gotcha, DO NOT INDENT THE FIRST/LAST lines of the heredoc declaration.
EDIT The benefit being that you can mix single and double quotes as much as you like, you only have to worry about the JS quoting - PHP variables are interpolated without the quotes. You can further wrap curly quotes around your PHP variables like {$this} to make it easier to read, but also to delineate $this and {$this}tle.
I would us the following instead of escaping, this is more readable to me:
$delurl = "delete_dish.php?dish_id=".$row['id'];
$img = "<img src = 'images/delete.png'>";
?>
<?=$img?>
You can, may and should escape when handling stuff like this:
echo "<a href=\".$delurl.\"";
echo " onclick=\"return confirm('Are you sure you want to delete.')\">".$img."</a>";
lg,
flo
I am having trouble echoing this line. Is anyone willing to help?
echo '<li>'.$row->subject.'</li>';
As your string is enclosed in single-quotes, you have to close the quotes, concatenate the variables, and re-open the quotes :
echo '<li><a href="http://stackoverflow.com/thread-'
. $row->tid
. '-1-1.html">'
. $row->subject
. '</a></li>';
(split over several lines to improve readability)
Else, you could use a double-quoted string, to have variables interpolation -- escaping the double-quotes that are inside the string :
echo "<li>{$row->subject}</li>";
Your quotes are mismatched.
....'-1-1.html">'....
<?php
echo <<<_HTML_
<li>
{$row->subject}
</li>
_HTML_;
?>
You are echoing one single quote too much in the middle of this part: '-1-1.html'">'. This single quote is currently closing the string and will result in a parse error.
If your editor is supporting syntax highlighting, you will be able to notice a difference in colour after this quote.
To solve this problem, change this your code to:
echo '<li>'.$row->subject.'</li>';
?>
<li>
<a href="http://stackoverflow.com/thread-<?=$row->tid?>-1-1.html">
<?=$row->subject?>
</a>
</li>
like this:
echo '<li>'.$row->subject.'</li>';
There is a problem in this code I can not detected
<?php echo "<a href ='$rows['Link']'> .$rows['UploadName']</a> "; ?>
Do you find you have a solution???
Thank you very much.
My guess is that your problem is that it isn't writing out the data in $rows['Link'] ... if that is the case, then your solution is to change it to {$rows['Link']} ... actually, you'll probably want to change both, since it looks like you started doing string concatenation and then switched halfway through.
So:
<?php echo "<a href ='$rows['Link']'> .$rows['UploadName']</a> "; ?>
becomes:
<?php echo "<a href ='{$rows['Link']}'>{$rows['UploadName']}</a> "; ?>
See: The PHP Manual on Variable Parsing in strings
It should be:
<?php echo "<a href ='{$rows['Link']}'>{$rows['UploadName']}</a>"; ?>
Or:
<?php echo "<a href ='{$rows['Link']}'>" . $rows['UploadName'] . "</a>"; ?>
There's a problem in parsing variables in the string. Use curl braces:
<?php echo "<a href ='{$rows['Link']}'> .{$rows['UploadName']}</a> "; ?>
Take a look to this php.net page, under "variable parsing".
More alternatives:
<?php echo '' . $rows['UploadName'] . ''; ?>
or
<?=('' . $rows['UploadName'] . '')?>
Another alternative (that I tend to prefer, given I know that both 'Link' and 'UploadName' are valid indices of $row.
<?=$rows['UploadName']?>
I'm not sure what that does for readability for most people, but on color-coded IDEs, it tends to help, because the HTML isn't just seen as one giant ugly single-colored string.