简体   繁体   English

PHP-如何<a>使用获取请求</a>在标签中设置会话onClick

[英]PHP - how to set session onClick in tag <a> using get request

I have this code, I need to set session onclick with tag <a> using get request on another page. 我有这段代码,我需要在另一页上使用获取请求,使用标签<a>设置会话onclick。

For example, if I click item 4 it to send the value to URL and set session onclick link. 例如,如果我单击项目4,它将值发送到URL并设置会话onclick链接。

    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 onclick事件仅适用于浏览器中的javascript

In your code you rewrite kuy session for each item in the loop. 在您的代码中,为循环中的每个项目重写kuy会话。 When your page is rendered, you can find kuy with last product_id 呈现页面时,您可以找到最后一个product_id kuy

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'] 如果要使用product_id设置会话,则应在product_detail.php在这里,您可以从$_GET['sendVar']获取product_id ,并将此值设置为$_SESSION['kuy']

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM