I have a link that I would like to open a page in a pop up, the link and onclick work fine but open it in a new full window but when I add the part after '_blank' it stops working. Here's my code
echo '<li>'.$img.''.$item_name.'</li>';
I suspect there is a typo or a problem with my syntax but I can't find it.
Any help would be appreciated
echo '<li>'.$img.''.$item_name.'</li>';
echo '<li>'.$img.'test'.$item_name.'</li>';
You are missing some closing single quotes in the window.open arguments, and the arguments you are passing are slightly incorrect. _blank is a separate argument from URL (the first argument,) URL needs a closing single quote, and NAME needs an opening single quote. corrected code is below
echo('<li>' . $img . '' . $item_name . '</li>');
Related
I'm trying to get a URL to have a dynamic parameter based on the value of a variable.
Here's what Im doing
echo "The file name is ".$value.''.$value.''."<br>";
However, when I click on the corresponding link I get the following URL in the browser
http://localhost/HelloWorld/filespecificpage.php?filename=<?php echo $value ?> rather than the actual value in $value. Any help on how I can fix this would be appreciated.
PHP Noob here, appreciate the patience.
You're already in PHP script mode, you don't need <?php. You just need to concatenate the variable, like you did earlier in the line. You should also use urlencode() when substituting a variable into a URL parameter.
echo "The file name is ".$value.''.$value.''."<br>";
If you break the PHP String/Echo dont use the doublequotes, it makes your live much harder as you need ist.
For your question
echo 'The file name is ' . $value . '<a href="filespecificpage.php?filename=' . urlencode($value) . '>' . $value . '</a><br>';
An expample why single and not doublequotes. If you write an Hyperlink in HTML you use
Link description
and all is fine.
If you do it in an PHP echo with doublequotes you must escape all quotes.
echo "Link description";
Perfect look and way
echo '<a href="website" target="_blank" ' . $anyPHPvar . '>Link description</a>';
and you can use " for clear html and ' for PHP ;)
So, use singlequotes makes your life easyer and its a little bit faster and welcome to PHP ;)
So i'm trying to make a website without having any errors, however i keep getting this error:
line 31 column 107 - Error: Bad value display.php? url=A GUIDE TO THE
PROJECT MANAGEMENT BODY OF KNOWLEDGE for attribute href on element a:
Illegal character in query: not a URL code point.
And this is the part of the code that it is highlighting that is giving the error:
</tr><tr><td><a href='display.php? click=A GUIDE TO THE PROJECT MANAGEMENT BODY OF KNOWLEDGE'>
The '>' the symbol on the end is being highlighted, and it is repeating this for every row.
This is the line of the source code that is saying that is causing the error:
$book = $row['bookTitle'];
echo "<td><a href='display.php? url=".$book."'>\n" .$book."</a></td>";
Any ideas of how to stop this? Any help is appreciated :)
Your a tag has a space before the query string parameter:
<a href='display.php? url=".$book."'>
this should be:
<a href='display.php?url=".$book."'>
I'm not fully sure of the exact reason for the error but you're injecting raw random input into both a URL and an HTML document. You need to escape them properly:
For URLs: rawurlencode()
For HTML: htmlspecialchars()
Please note that the value of the href attribute contains a URL that's injected into HTML so you need both escaping mechanisms:
$book = $row['bookTitle'];
echo "<td><a href='display.php?url=" . htmlspecialchars(rawurlencode($book)) . "'>\n" .
htmlspecialchars($book) . "</a></td>";
I've also fixed what I assume is a little typo (you probably expect $_GET['url'] rather than $_GET[' url']).
I have a problem I can't solve by myself, don't know how simple it is to solve but I want to open this link in another frame:
<?php echo "<a href=details.php?id=$row[idProdukt]>$row[Produkt_Namn]</a>" ?>
tried to use taget but since it's html I couldn't really wrap my head around how to type it.
any help is greatly appreciated.
Just add the attribute to your anchor tag as usual. Make sure you use the name of the targeted iframe as its value:
<?php echo "<a href='details.php?id=$row[idProdukt]' target='framename'>$row[Produkt_Namn]</a>" ?>
I added quotes around your html attribute values as that is a good practice to be in. It prevents issues arising from errant or intentional spaces in attribute values.
First, you have error on array index, missing quotes. You can use this;
<iframe src="some_url" name="test">
.....
</iframe>
<?php echo "" . $row['Produkt_Namn'] . ""; ?>
The trouble is missing quotes around href attribute value and array key.
echo "{$row['Produkt_Namn']}";
See in action
I am trying to create a hyperlink using php. the hyper link is in a table..
this is my code:
echo"<tr><td>"click here</td></tr>";
I am getting an error
How can i fix this?
It should be
echo"<tr><td><a href='".$row['hyperPath'] . "'>click here</a></td></tr>";
You had an extra " after your tag. If you really want the " to be displayed you need to escape it first with \ like this:
echo"<tr><td>\"<a href='".$row['hyperPath'] . "'>click here</a></td></tr>";
You were also missing the closing quote for your href attribute (added before >click here)
try this
echo "<tr><td><a href='".$row['hyperPath']."'>click here</a></td></tr>";
What Im trying to do is write a script that grabs the url of thumbnails attached to posts in wordpress. It sounds really easy(as I'm sure the solution is) but I can't seem to get it to work, I keep getting syntax errors no matter what I try. The problem line is the second echo(Img src...). Any help would be greatly appreciated.
$image_id = get_post_thumbnail_id();
$image_url = wp_get_attachment_image_src($image_id,'archive-thumb');
$image_url = $image_url[0];
echo "<li class=\"recent-img-widget-li\"><a href='".get_permalink()."'>;
echo "<img src=\"".$image_url."\" width=\"120\" height=\"120\">";
echo "</a></li>";
Simply enough, you're not closing your first string after get_permalink(). Yo need another quote after the >.
You never close the first string. You just need a quote before the greater than on the first line (and possibly the second?). Look at the syntax highlighting that SO has.
A general guideline is to always look at the row above the one that is giving the error.
In this case you have forgotten to end the string in the last part of the first echo statement.
...ermalink()."'>;
Should be
...ermalink()."'>";
For one you should close that first echo. Missing the closing "