Php Can';单击按钮时不重定向
所以我想在按下按钮时重定向到“editcomment.php” 我尝试过将name改为onclick,也尝试过将按钮放在标签中以使用hrefPhp Can';单击按钮时不重定向,php,html,Php,Html,所以我想在按下按钮时重定向到“editcomment.php” 我尝试过将name改为onclick,也尝试过将按钮放在标签中以使用href echo("<button class='col-sm-2 border1' name='myButton1()'>"); echo("<p>Bokad</p>"); echo("</button>"); session_start(); $bokning = 0; $_SESSION['bokningar
echo("<button class='col-sm-2 border1' name='myButton1()'>");
echo("<p>Bokad</p>");
echo("</button>");
session_start();
$bokning = 0;
$_SESSION['bokningar'] = $bokning;
function myButton1(){
$bokning = 1;
header("Location: editcomment.php");
}
echo(“”);
回声(Bokad);
回声(“”);
会话_start();
$bokning=0;
$\会话['bokningar']=$bokning;
函数myButton1(){
$bokning=1;
标题(“位置:editcomment.php”);
}
如前所述,我希望它重定向到editcomment.php并将$bokning更改为1,但什么也没有发生。有什么想法吗?首先,不能使用PHP函数进行重定向。这里有两个解决方案。这两种解决方案都假定您没有提交包含数据的表单。如果你这么做,有一个完全不同的方法 请注意下面完整URL的使用
<a href="http://yourdomain.com/editcomment.php">
<button class='col-sm-2 border1' name='myButton1()'>
</a>
第二个是使用javascript。在你的网页底部,这样做
<script>
function myButton1() {
window.location.replace("http://yourdomain.com/editcomment.php");
}
</script>
函数myButton1(){
window.location.replace(“http://yourdomain.com/editcomment.php");
}
有了以上内容,您必须将onClick()放回按钮。您不能直接用html元素调用php函数。哦,我明白了,有没有办法用php为$bokning指定一个值?如果需要,您可以将它放在html中的隐藏输入中。我不完全理解目的,但你可以这样做:echo“”;我试图创建一个变量,该变量根据我按下的按钮(我有多个按钮)的不同而变化,然后我将使用该变量根据$bokning的值来改变某个数据库值