PHP - 如何在标记<a> using get request

时间:2018-01-13 18:07:05

标签: javascript php html session

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

1 个答案:

答案 0 :(得分:0)

onclick事件仅适用于浏览器中的javascript

在您的代码中,您为循环中的每个项重写kuy会话。呈现网页时,您可以找到kuy

product_id

如果您想使用product_id设置会话,则应在product_detail.php中执行此操作 您可以在此处从product_id抓取$_GET['sendVar']并将此值设置为$_SESSION['kuy']