I have this code, I need to set session onclick with tag <a>
using get request on another page.
For example, if I click item 4 it to send the value to URL and set session onclick link.
while(list($product_id,$product_title,$product_name) = mysqli_fetch_row($result)){
echo "<tr>";
echo "<td>".$product_id."</td>";
echo "<td><a href='product_detail.php?sendVar=".$product_id."' onclick='".$_SESSION['kuy'] = $product_id."'>".$product_title."</a></td>";
echo "<td>".$product_name."</td>";
echo "</tr>";
}
Sorry i'm not good at english
onclick
event works only with javascript in browser
In your code you rewrite kuy
session for each item in the loop. When your page is rendered, you can find kuy
with last product_id
If you want to set session with product_id
, you should do it in your product_detail.php
Here you can fetch product_id
from $_GET['sendVar']
and set this value to $_SESSION['kuy']
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.