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
Related
Hello dear programmers,
I have a problem with the echoing of a html phrase with an onclick function that executes a javascript function. I want to build a tabpage, for a image gallery.
The echo:
echo "<div class='albumitem'><a class='tablinks' onclick='openAlbum(event, '".$album."')'><h1 class='galleryheader'>".$album."</h1></a><div id='".$album."' class='tabcontent'>";
Everything goes well, except the passing of the variable in the onclick function, as you can see here. What actually the HTML looks like:
<a class="tablinks" onclick="openAlbum(event, " aubing')'=""><h1 class="galleryheader">Aubing</h1></a>
But this onclick event has to look like this:
onclick="openAlbum(event, 'Aubing')"
Is there a way to actually realise this or do I have to find an other option?
I actually tried switching " with ', didnt go very well....
Thank you for everybody that tries to help
Try this:
echo "<div class='albumitem'><a class='tablinks' onclick='openAlbum(event, \"$album\")'><h1 class='galleryheader'>".$album."</h1></a><div id='".$album."' class='tabcontent'>";
see escaped double quotes in the onclick definition
addslashes is what you are looking exactly.And also you have to remove the single quotes in variable.Try to do the following way.
echo "<div class='albumitem'><a class='tablinks' onclick='openAlbum(event, '".addslashes($album)."')'><h1 class='galleryheader'>".$album."</h1></a><div id=".addslashes($album)." class='tabcontent'>";
Hope this help.
An alternative:
$escapedString = htmlspecialchars('This is a test string: < > & \' " end.', ENT_COMPAT);
echo "<div onclick='alert(this.dataset.name)' data-name=\"$escapedString\">Click Me</div>";
This approach avoid quotes inside function, no quotes nesting.
I am trying to pass a variable from one page to another by appending it to the URL like this-
<a href='single.php?name=".$m['Title']." ' class='movie-beta__link'>
and in the next page(single.php), I am getting the url as-
$title= $_GET['name'];
echo $title;
But nothing is displayed and my URL looks like this-
http://localhost/mdb/single.php?name=
Can someone please point out if I am missing something here.
Try this
<a href='single.php?name=<?php echo $m['Title']; ?>' class='movie-beta__link'>Title</a>
You're getting your single and double quotes mixed up. With single quotes you have to append variables and with double quotes you can put them inside. But when you're outside of <?php tags you can use <?= to echo a variable.
<a href="single.php?name=<?= $m['Title'] ?>" class="movie-beta__line">
This will work above:
<a href='single.php?name=<?php echo $m['Title']; ?>' class='movie-beta__link'>Title</a>
if all this is in php echo, use <a href='single.php?name='".$m['Title']."' class='movie-beta__link'>Title</a>
And its good to avoid underscores on you class names
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;
I have this php line which works fine:
echo "<p>" . $post['message']. "</p>";
But I want to change it so it will link to my page (not to a single post). So it should look like that.
echo "<p>" . $post['message']. "</p>";
I have tried a lot many proposition gathered on different website, but each time I am getting an error.
Any idea ?
Thanks a lot!
Using single and double quotes, you avoid escaping issues. Try this:
echo '<p>'. $post['message']. '</p>';
i see that you didn't escaped from double quote that closes href attribute:
echo "<p><a href=\"https://www.facebook.com/rscmovement\" target=\"_blank\">"
I guess You have missed the back slash () before " after www.facebook.com/rscmovement.
"https://www.facebook.com/rscmovement\" "\"target=\"_blank\">" will
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>';