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
Related
When I try to use this:
<?php
$html = "<p id="test"><input class='is' id='live' type='checkbox' onclick='update(".htmlspecialchars($myid).");'></p>";
?>
If $myid is a number the above works fine. If it contains text like mytext_30, then onClick I get a console message that mytext_30 is not defined. How in the top syntax I can include some kind of quotas for the result to be always like this:
<input .... onclick='update("30")'/> or
<input .... onclick='update("mytext_30")'/>
?
Thank you in advance.
Quotes you are using are mislead for PHP. try this:
$html = "<p id=\"test\"><input class='is' id=\"live\" type='checkbox' onclick='update(\"".htmlspecialchars($myid)."\");'></p>";
The problem belongs to missing escaping of the quotes. Thats easy to fix.
But first, you should decide on a way you will use. Preferred way to write tags in HTML is to always use quotes ". But at least, you should not mix quotes and apostrophes. Decide for one way and use them, but not switch between them here and there.
The best way here is, to use quotes for the tags, and apostrophe for the php string. With using apostrophes for this, you have clean HTML and don't need to escape anything.
$html = '<p id="test"><input class="is" id="live" type="checkbox" onclick="update(' . htmlspecialchars($myid) . ');"></p>';
I am struggling with an issue which I need a little bit of help with, basically I have created a search bar and when the results come up I only want the 'Session 1' or 'Session 2' to be href'd. Not the whole thing. A photo below:
img http://gyazo.com/eb677171c15b075f1fb4137d28227b3a.png
I would just like the Sessions to be hrefed but the paragraphs just.
My code below:
echo "<p><a href='../pages/session.php</a>".$results['1']."'><h3>".$results['title']."</h3>".$results['text']."</p>";
Linking to my DB
Note that is not all of my code just where I believe the issue lies.
You placed </a> slightly wrong. The correct solution would be like this:
echo "<p><a href='../pages/session.php'>{$results['1']}</a><h3>{$results['title']}</h3>{$results['text']}</p>";
If you use double quotes, you do not need to concatenate variables into your string, they are also validate within the string.
UPDATE
To display only the headlines as links try this:
echo "<a href='../pages/session.php'><h3>{$results['title']}</h3></a><p>{$results['text']}</p>";
You have missed a bracket in ur a tag.It is like <a href='whatever'>blah</a>
Do you just want to href $results['1']? Here you go.
echo "<p><a href='../pages/session.php'>".$results['1']."</a><h3>".$results['title']."</h3>".$results['text']."</p>";
I'm a beginner PHP programmer, and I was wondering what was wrong with my code.
Here is the small excerpt from the affected spot:
echo "<form action='?tab=4' name='toedit5' method='get'><input value='text' onblur='edit('toedit5')' /></form>";
In Chrome's Developer Tools, the form element totally disappears, and the edit('toedit5') becomes edit(' toedit5').
The edit() function doesn't execute.
Is there anything wrong with this one line of code? Otherwise it is outside code messing with it. Sorry I didn't include it, but I don't know what to include. If you need more information, please tell me.
Thanks.
You need to escape your quotes inside your quoted echo'd statement, like this:
<?php
echo "<form action='?tab=4' name='toedit5' method='get'>";
echo "<input value='text' onblur='edit(\"toedit5\")' />"; // escaped..!
echo "</form>";
?>
It helped me to think about it like this when I was starting out: how does your browser know if the second single quote in onblur='edit('toedit5')' is closing your onblur statement or opening up the parameter? In this example, your browser will pair up the first 2 quotes it sees and assign that to the onblur attribute, i.e.: onblur='edit(' only!
Update 1:
Using the code above, I inspected a quick PHP page I created in Chrome's developer tools and was able to see the following (form available for inspection):
You really should use the more standard double quotes around the HTML properties and use single quotes around your string, with escaped single quotes within the javascript method calls. Like this:
echo '<form action="?tab=4" name="toedit5" method="get"><input value="text" onblur="edit(\'toedit5\')" /></form>';
Hi I am transferring html code to php code, but i get some problems.
For example in html I am using <ul div class="country city">...</ul>, it contains two classes (country & city),
But when I using PHP, I need to change it to echo "<ul div class=country city>...</ul>" since php does not accept "" in the middle. And as a result, the system only accept the first class(country) instead of two classes.
So could I ask how to change it,
Thanks :-)
use simple quote for example as HTML accept it as double quote
echo "<ul div class='country city'>...</ul>"
You can also escape your " so PHP can accept it:
echo "<ul div class=\"country city\">...</ul>"
You can swap the quotations to make them work. like this
echo "<ul div class='country city'>...</ul>"
If you want to introduce any variable in between, you can add this by
echo "<ul div class='country city".$variable."'>...</ul>"
This is called concoction
I found this tutorial that explains what I want to do using html but when I echo out the code with a get variable there is no affect to the page. I would use, for example, the following code:
echo "<a href='post.php?id=".$id."#Comments'>Click here to go to the comments</a>";
echo "<a title='Comments'>Comments</a>";
I presume the problem is to do with the get variable, so would I have to end it, some how, before using the # symbol?
The problem actually lies in your HTML, because the anchor should be parsed correctly by browsers regardless of the query string.
Page anchors use the name attribute instead of the title attribute:
<a name='Comments'>Comments</a>
You can also apply this to the id attribute of any element:
<h2 id='Comments'>Comments</h2>
To define jump-labels you have to set a name and/or id-attribute:
echo "<a title='Comments' name='Comments' id='Comments'>Comments</a>";