我想从 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>
任何帮助都感激不尽。
繁华开满天机
相关分类