I created a function that requires one parameter to be passed into it but I need that parameter to come from another script. How do I embed the variable into a link then put that variable into the function in another script? I know I need to utilize $_GET, isset($_GET['']) and a href but I just can't put it all together.
$_GET is collection of of query string parameters. If you had a url like: test.php?param1=foo¶m2=bar you can access foo by $_GET['param1'] etc..
Use $_REQUEST['something']
Your link must be:
Click Me
Inside test.php
if(#$_REQUEST['something']=="something"){
echo $_REQUEST['something1'];
}
When you click Click Me, test.php would echo "test".
Related
I am beginner in php.I want to call a give click action to the text when user click on text it has to call the php function and I am passing parameter to that function.
the code is like this
this is in php;
for($v=0;$v<10;$v++){
echo '.$version[$v].';
}
I want to call method graph($v) with passing parameter when user click on '.$version[$v].' this text.
you need to use JavaScript for check where the user clicks and use Ajax to communicate with the server
I'm working with PHP and in this instance I want to pass $_SESSION which I've already assigned with my currentUser object. This works fine.
I've used the header function to pass variables between pages such as header('Location: example.php?uID='.$uID) and then using GET to receive this value.
However, instead of using a header to automatically redirect, I want to use a href so that the user has to click on a link, which then initiates the redirect.
The problem is that I use the anchor (<a>) inside the PHP tags and I can't pass variables using it inside the HTML tags.
I'd be very grateful for the solution and happy to elaborate. Thank you!
You can do it that way :
//assuming that the user id is stored in the 'uID' field of $_SESSION
Redirect me !
I've got a php script which builds a html table via echoing data, But i want to add a link onto one of the values and pass that value to the next page.
<td><a href='redirect.php'><?php $_SESSION['WR'] = $row['WorkOrdRef'];echo $row['WorkOrdRef'];?></a></td>
is the line in question but this will only pass the last value added to the table.
Oh, it doesnt work like this. the php code gets executed no matter if you click the link.
I guess the easiest way to do this is to pass it as a get parameter.
html page:
<?=$cellContent?>
redirect.php:
$clickedcell = $_GET['clickedcell']
now the $clickedcell will have the data from the previous page about what cell did the user click.
If you want to use session for some reason, you still have to pass it with GET or POST and store it after the user clicks.
hopefully this is understandable and good luck with your project.
you can change the session by get method also it is possible building by javascript
in the same page add this
if(isset($_GET["clicked"])){
$_SESSION['WR'] = $row['WorkOrdRef'];
$redirect'<META HTTP-EQUIV="REFRESH" CONTENT="0;URL='.$adres.'/"> ';
return $redirect;
}
and then change your url
<td><?php echo $row['WorkOrdRef'];?></td>
I am working with some anchor tags in HTML where i need to carry over some arguments from the first url to the second url
My Link
My current URL is - oldpage.html?arg=value
But the "My Link" redirects to -
newpage.html
and not
newpage.html?arg=value
How do i carry over the value of arg ?
If you want to just copy a known variable over, it's as simple as
<?php echo "My Link" ?>
and then oldpage.html?arg=value would produce a link to newpage.html?arg=value.
However, if you want to pass over the entire query string, you can achieve this with the $_SERVER["QUERY_STRING"] variable.
<?php echo "My Link" ?>
This will propagate the entire query string to the new page. So if you accessed the current page with oldpage.html?arg=value&color=green, the link would point to newpage.html?arg=value&color=green.
Alternatively you could use http_build_query, allowing you to add extra parameters or modify the existing query string as you see fit.
<?php echo "My Link" ?>
Using this, navigating to the current page as oldpage.html?arg=value would produce a link to newpage.html?arg=value&foo=bar.
My Link
Or you could do this:
My Link
But that is only if your server allows you to use SERVER variables.
My code is something like this
Page A.php: has Click
Page B.php: has <a name="comment">Comment</a> tag and also need variable 'Id' and 'Pagenumber'
It doesn't work... help me please.
put the # after the Get variables. Click