0

I want to change a variable by clicking a link, this is what I tried:

<a href="#" name="link">link</a>

$var = 0;

if (isset($_GET["link"])) {
  $var = $var + 10;
}

But it doesn't work, what am I doing wrong?

I use XAMPP to run my index.php file.

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189

2 Answers2

0

Here is your answer i will give help more if you have any problem

<?php
$var=$_GET['link'];
if($var==null){
$var = 0;
}
if($var!=null){
  $var = $var + 10;
}
?>
<h1><?php echo($var);?></h1>
<form action="">
  <input type="hidden" id="link" name="link" value="<?php echo($var);?>"><br>
  <input type="submit" value="Submit">
</form
Ravi
  • 5
  • 1
0

Here is another example for your question


<?php
$var=$_GET['link'];
if($var==null){
$var = 0;
}
if($var!=null){
  $var = $var + 10;
}
echo "<a href=index.php?link=",urlencode($var),">Click=  ($var)</a>";
?>

change index.php as per your file name

Ravi
  • 5
  • 1
  • I can't try it now, but I'll get back to you if I'd need more help. –  Jun 07 '20 at 12:46