How To Pass Variables Between 2 PHP Files?
then in PHP
if (isset($_GET['clicked'])) {
$clicked = (int)$_GET['clicked'];
} else {
$clicked = 0;
}
Solution 2:
code is here,
<?php
if($_REQUEST['click'] == 1)
{
echo "One was clicked.";
}
else if($_REQUEST['click'] == 2)
{
echo "Two was clicked.";
}
?>
<html>
<body>
<a href="two.php?click=1">Click here for 1.</a>
<a href="two.php?click=2">Click here for 2.</a>
</body>
</html>
Solution 3:
You can pass variables by using GET
or POST
method.
Here is simple GET (query string)
method.
main.php :
<html>
<body>
<a href="two.php?btn=One">Click here for 1.</a>
<a href="two.php?btn=Two">Click here for 2.</a>
</body>
</html>
two.php :
<?php
if(!empty($_GET['btn'])) {
echo $_GET['btn'] . " was clicked";
}
?>
Solution 4:
This question is asked so many times:-
How to pass a variable value between 2 php files?
How to pass variables between php scripts?
Pass variables between two PHP pages without using a form or the URL of page
passing value between two php files
PHP Pass variable to next page
Passing PHP variables between scripts
passing variables between functions and files in php
PHP Passing variables between two files
Passing multiple variables to another page in url
Use SESSIONS variables between different php files
how to pass variables between 2 php pages when the latter called with require()
Transfer variables between PHP pages phpbb 3.1 passing variable between 2 pages
Post a Comment for "How To Pass Variables Between 2 PHP Files?"