我想從 HTTP GET 請求接收數(shù)據(jù)并將其存儲在一個 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>任何幫助都感激不盡。
在通過超鏈接重定向到另一個頁面之前從 HTTP GET 請求接收數(shù)據(jù)
阿晨1998
2021-11-13 16:04:11
