php - How to pass value from one page to another page by clicking text on page
Get the solution ↓↓↓I am newbie to web programming and working on web application development(first project) where i have some text on page and after clicking this text i want to pass some fixed text to other page in PHP as explained here
Page1
<html>
<head>
</html>
<body>
<a href="#" value="fixed text">some text </a>
</body>
</html>
Page2 should be able to get value when i click on page1. How can i implement it?
Answer
Solution:
You should pass arguments with url:
<a href="xyz.php?value=fixed text">some text </a>
And in thexyz.php
or what ever file name for php:
<?php
$value = ! empty($_GET['value']) ? $_GET['value'] : '';
?>
Reference: PHP's $_GET
Whatever data you have in url query string. e.g.xyz.php?par1=one&par2=two&par3=three
You get key value pairs in$_GET
.
So, you will get
$_GET
as
array(
'par1' => 'one',
'par2' => 'two',
'par3' => 'three'
);
Answer
Solution:
page 1
<html>
<head>
</html>
<body>
<a href="page2.php?val=sample" value="fixed text">some text </a>
</body>
</html>
page2.php
<?php
$value=$_GET['val'];
?>
<html>
<head>
</html>
<body>
<?php
echo $value;
?>
</body>
</html>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: the payload is invalid.
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.