所以我想在按下按钮时重定向到“ editcomment.php”。
我尝试将名称更改为onclick,也尝试将按钮放在标签中以使用href。
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");
}
如上所述,我希望它重定向到editcomment.php并将$ bokning更改为1,但是什么也没有发生。有什么想法吗?
答案 0 :(得分:1)
首先,您不能使用PHP函数进行重定向。这是两个解决方案。两种解决方案都假定您不提交包含数据的表单。如果您要这样做,则有完全不同的方法。
请注意以下完整网址的使用。
<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>
使用上述方法,您必须将onClick()放回按钮中。
答案 1 :(得分:0)
您可以使用ajax将数据传递到其他页面上的按钮单击事件,而无需页面重定向
$(document).ready(function(){
$("#submit2").click(function(){
$.ajax( {
url: "<?php echo site_url();?>Home/get_regiter_data",
method: "POST",
data: $("#registrationForm").serialize(),
dataType: "text",
success: function(strMessage) {
// alert("Registration success");
window.location.href = '<?php echo site_url();?>Login';
// $(".Next-btn-div").hide();
}
});
});
});
答案 2 :(得分:-2)
您不能直接使用html元素调用php函数。