I have pretty straight forward question:
What would be the correct syntax for this be?
onclick="location.href = '/xxx/xxx?key='.'<? $value[0]->pass_key; ?>'"
At the moment, this redirect's to my page /xxx/xxx/?key, but leaves out my pass_key, which i need to generate data on the resulting page.
UPDATE
Was a mistake not to use
<?= ?>
which is the same as
<? echo ?>
I've updated it in my code still no key is passed along.
This statement resides in this tag:
<td>
SOLVED
Thx to chinnu and y'all!
And what's up with the downvote? :( just because it's a simple mistake/question. .
Prudes.
onclick="location.href = '/xxx/xxx?key=<?php echo $value[0]->pass_key; ?>'"
Related
I have this code in my page1.php which passes 2 variables.(im using pdo btw)
<a type="button" href="PT-ContractsInfo.php?id=<?php echo $pt['TL_Code']?>&client=<?php echo $pt['CLIENT_ID']?>" class="btn bg-green" >View</a>
...And my code for page2.php
<?php
$id = $_GET['id'];
$client = $_GET['client'];
<?
But it outputs an error "Undefined index: client"...
Is there something wrong with the codes?Ty
you have semicolon missing
<?php echo $pt['TL_Code']?>
should be
<?php echo $pt['TL_Code']; ?>
but anyways you want to be careful when echoing variables in an url, you should encode the variable in url format first
like
<?php echo urlencode( $pt['TL_Code'] ); ?>
you can also use http_build_query() which would be even cleaner
I have created a custom wordpress post type everything works but my client asked me to insert a function that doenst show the button if the link field is empty that is also working but when I want to display the tekst or link the part where the php is inserted just doesnt shows up what am I doing wrong
I am able to get the data on other parts of this php file but not in this part of the page
<?php
$linktitle = $day_aray=get_field("under_shoe_button_title");
$linkexist = get_field("under_shoe_button_link");
echo($linktitle);
if (empty($linkexist)) {
echo '<html> <p></p></html>' ;
}
else {
echo '<html>
<a href="google.nl" class="button primary is-bevel box-shadow-3 box-shadow-4-hover expand" style="border-radius:5px;"
</html> <?php echo($linktitle); ?> <html><span></span>
<i class="icon-shopping-cart"></i></a>
</html>';
}
?>
If you would look carefully, you would notice, that you are echoing a string where, inside the string, you are trying to echo again. Even with little programming knowledge, you should understand, that it is not logical to do that.
The same goes for php opening <?php tag. You opened the tag at start of the page and later on, inside a string, you are trying to open it again. This does not work.
Instead, close the string (or escape it) and then add the echo option.
echo '<html>
<a href="google.nl" class="button primary is-bevel box-shadow-3 box-shadow-4-hover expand" style="border-radius:5px;"
</html>';
echo($linktitle);
echo '<html><span></span>
<i class="icon-shopping-cart"></i></a>
</html>';
And please, read the comments to you question and learn basic HTML
There are so many things wrong in your code
Firstly you are using echo inside echo you should use concatenation instead.
so you want to echo it like this
echo '<your html code>'.$linktitle.'<your other html code>';
Also your html code is wrong coz u are using many html tags.
Im trying to add a PHP variable to a href url
This is the code:
PHP
$uid= $_SESSION['userid'];
HTML
<a href=http://example.com/uid= <?php echo ".$uid."?> /a>
How do you add, when I do it, this is what it redirect too: http://example.com/uid=.
Try this,
<?php
#session_start();
$uid= $_SESSION['userid'];
?>
<a href="http://example.com/?uid=<?php echo $uid; ?>" >Your link text</a>
echo "link description";
Perhaps something like this:
print '<a href=http://example.com/?uid=' . $uid . '>Link</a>';
try this
<?php
$url = 'https://www.w3schools.com/php/';
?>
PHP 5 Tutorial
Or for PHP 5.4+ (<?= is the PHP short echo tag):
PHP 5 Tutorial
or
echo 'PHP 5 Tutorial';
This is one of the most helpful
echo "<td>".($tripId != null ? "<a target=\"_blank\"href=\"http://www.rooms.com/r/trip/".$tripId."\">".$tripId."</a>" : "-")."</td>";
It will work!
This will work
<a href=http://example.com/?uid= <?php echo $uid ?> Myurl</a>
Try this:
<a href=http://example.com/uid= <?=$uid?> /a>
You're doing a couple things wrong.
In HTML you should quote attribute values such as href
In PHP you're not concatenating anything, just echoing
You forgot the link text
For readability, you can (probably) use the <?= shorthand instead of <?php echo
<a /a> is broken tag syntax. Should be <a>...</a>
End result is this:
Link Text
Im trying to show GET variable data in a textarea. I tried may solutions in StackOverflow but none of them worked. I have no idea why. Can you please tell me if I'm missing something.
My Story
I have a link on a page and href is /index.php?page=contact-us&performance=Lamborghini
and it takes me to the Contact Us page and the url is still /index.php?page=contact-us&performance=Lamborghini which is what I want.
So, Im tyring to grab performance variables's content which is Lamborghini and print it in a textarea which is
<textarea name="m62b34fbrp__32" cols="19" rows="7" class="cms_textarea" id="fbrp__32"></textarea>
So what I did is added <?php $performanceInfo= $_GET['performance']; ?> to the top of my page. Then added $("#fbrp__32").val(<?php echo $performanceInfo; ?>); in my script.js file. But it never prints Lamborghini in the textarea.
When I try $("#fbrp__32").val('<?php echo $performanceInfo; ?>'); (Notice the ' marks) it prints <?php echo $performanceInfo; ?> in the textarea.
When I <?php echo $_GET["performance"]; ?> it prints Lamborghini fine too.
Can you guys tell me why its not working for me?
NOTE : I cant edit the textarea manually as it is generated using a plugin Thanks a lot.
PHP Parse will not parse .js files, you will need to do this outside of the .js file. If not you will need to in your webserver config file set to parse .js files as PHP files.
EDIT
You mentioned that you added <?php $performanceInfo= $_GET['performance']; ?> to the top of the page and then $("#fbrp__32").val(<?php echo $performanceInfo; ?>); to your script.js file. This will not work as per default configuration script.js or any .js file will not be interpreted by the PHP parser. so your statement $("#fbrp__32").val(<?php echo $performanceInfo; ?>); will cause a syntax error.
The best way to handle it without changing server configuration would be to do this at the top of your page.
<script type='text/javascript'>
var performance = "<?php echo $_GET['performance']; ?>";
</script>
and in your script.js file do $("#fbrp__32").val(performance);
Try this
<textarea name="m62b34fbrp__32" cols="19" rows="7" class="cms_textarea" id="fbrp__32">
<?php echo $_REQUEST['performance']; ?></textarea>
OR in JS
$(document).ready(function(){
var performance='<?php echo $_REQUEST["performance"]; ?>';
$("#fbrp__32").val(performance);
});
Just add the following right before the textarea (in your PHP/HTML-file, not JS-File!):
var performance = <?php echo '"' . htmlspecialchars( $_GET['performance'] ) . '"'; ?>
$("#fbrp__32").val(performance);
Just set value directly using PHP
<?php
$performanceInfo= $_GET['performance'];
?>
JQuery is a bit tricky.Instead try simple javascript for setting value:
document.getElementById("Enter Here Textarea Id").value = <?PHP echo $_GET['performance']; ?>
Ok. Finally this is the solution which worked for me.
In the php file I put
<?php
$performanceInfo= $_GET['performance'];
echo "<script>";
echo "$('#fbrp__32').val('$performanceInfo');";
echo "</script>";
?>
Its weird other solutions didnt work for me for somereason.
Try this
var value = <?php $performanceInfo= $_GET['performance']; ?>
$("#fbrp__32").val(value);
NB: php tags will not not render in js files
In PHP i'm using the following code to put a banner at the top of my website.
$eventinfo = simplexml_load_file("eventinfo.xml");
<div id="eventinfo"><?php foreach($eventinfo->children() as $child){ $final = $child["name"]."...<a href='".$child["adr"]."'>more info...</a>"; } ?>
</div>
The XML doc is available at the following: http://eastsidespeedway.raceresults.co/eventinfo.xml
If you go to http://eastsidespeedway.raceresults.co/index.php you'll see that the more info... link is showing up twice. One with the correct link, and the other with a link to the same page (index.php).
Can anyone shed some light on what I'm doing wrong?
Also. If you see anything that I'm doing wrong, or you know something that's easier - let me know! This is my first time using XML/PHP so I'm kinda just wingin it. Haha.
this will work for you
<?php
$doc = new DOMDocument();
$doc->load('http://eastsidespeedway.raceresults.co/eventinfo.xml');
$title = $doc->getElementsByTagName('title');
$link = $doc->getElementsByTagName('link');
//print_r($eventinfo);
?>
<div id="eventinfo">
<?php echo $title->item(0)->getAttribute('name'); ?>
<a href='<?php echo $link->item(0)->getAttribute('adr'); ?>'>More Infoo..</a>
</div>
If you look at your source:
<div id="eventinfo">5/18/2013 - Al Smiley Memorial...<a href=''>more
info...</a>...<a href='http://www.eastsidespeedway.com/dirt.html'>more
info...</a></div>
You've got two hyperlinks- one href is blank meaning that it will redirect to the current page, check your HTML code first to see if you've accidentally duplicated the element, otherwise look at the construction of your string in the php code