0

I am working on HTML/PHP table that generates multiple hyperlinks to the same page. The difference is depending on which link is clicked the session variable is set on that. However it always returns the link for the last hyperlink created. Is there a way to set the variable based on which hyper link is used. The data used is pulled from a sql server. It is echoing the correct result for each row on what the session variable should be. Sample code, $x is the array i am pulling from:

<?php
if($x[$i] != ""){

?>
<a href="file.php" onClick="<?php $_SESSION['test'] = $x[$i]?>; return popup(this, 'notes')" . SID . >To page</a>

<?php
echo $_SESSION['test'];
}

$i++;
//$_SESSION['test'] = $email;
 ?>
L.Smart
  • 1
  • 3
  • Required reading: [What is the difference between client-side and server-side programming?](https://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – ADyson Jul 07 '22 at 15:43
  • `onclick` is for running **JavaScript** functions (as per any documentation or examples you will ever see of that option). It cannot execute PHP. The PHP code you've written there will execute along with the rest of the PHP you wrote - i.e. before your page loads, while it's in the process of generating the page. – ADyson Jul 07 '22 at 15:44
  • What you need to do is put some parameter in the URL of the link, e.g. `href="file.php?id="`. Then when the link is clicked, the reuqest will go to file.php, and in the PHP code there you can do `$_SESSION['test'] = $_GET["id"];` to assign the value which was clicked to the Session variable. – ADyson Jul 07 '22 at 15:45

0 Answers0