我想从 HTTP GET 请求接收数据并将其存储在一个 PHP 变量中,然后再重定向到另一个页面。这是代码。 <?php session_start(); require("dbconfig.php");?></html><head><a href="https://www.google.com/" class="btn btn-success" id="link" type="button" >Click me</a> <script type="text/javascript"> jscounter=1; jscounter++; document.getElementById("link").onclick = function () { alert("javascript counter variable is " +jscounter); window.location = "?js_var=" + jscounter; } </script></head><body></body><?php if (isset($_GET['js_var'])) { $counter = $_GET['js_var']; echo "PHP counter variable is ".$counter; $squery = "update mycounter set counter=$counter"; if(mysqli_query($dbc, $squery)) { echo "Counter added to db successfully to DB"; } else { echo mysqli_error($dbc); } }?> </html>当超链接中没有提到链接时,上面的代码有效,如下所示。<a href="#" class="btn btn-success" id="link" type="button" >Click me</a>任何帮助都感激不尽。
1 回答
繁华开满天机
TA贡献1816条经验 获得超4个赞
您可以保留<a href>
代码原样。完成获取数据并保存后。只需重定向到所需的页面:
header('Location: http://your.desired.link/');
添加回答
举报
0/150
提交
取消