你好,当有人单击div元素时,我想在php中设置$ _POST值,这是我的代码的一部分:
<?php
$looperone = 1;
$judulcountquery = "SELECT nomorsoal FROM soal";
$judulcountrun = mysqli_query($konek,$judulcountquery);
if ( $judulcountrun == FALSE ) {
die(mysqli_error());
} else {
}
$judulcount = mysqli_num_rows($judulcountrun);
$amountofrows = $judulcount;
while($looperone == 1) {
$judulherequery = "SELECT * FROM soal WHERE nomorsoal = $amountofrows";
$judulsatuqueryconnect = mysqli_query($konek,$judulherequery);
$judulsatufetch = mysqli_fetch_assoc($judulsatuqueryconnect);
if($judulsatufetch != NULL) {
$judulsatu = $judulsatufetch['judul'];
} else {
break;
}
$judulnya = $judulsatufetch['judul'];
echo "<div class=\"head-main-recenttest-result\" style=\"text- decoration:none;\">". "<a href=\"bacasoal.php\">".$amountofrows.".".$judulnya." </a></div>";
$looperone++;
$amountofrows--;
}
?>
echo输出示例:
<div class="head-main-recenttest-result" style="text-decoration:none;">
<a href="bacasoal.php">Latihan 1</a>
</div>
如您所见,只有在不提供发布数据的情况下,人们才能重定向到链接,有人知道该方法吗?我也是新来的,所以我不能很好地问
通过你的代码的外观,你不发送任何职位variable
的bacasoal.php
。如果您只想提交,那么就足够了。
<form method="post" action="bacasoal.php">
<div class="head-main-recenttest-result" style="text-decoration:none;">
<input type="submit" name="button" value="Latihan 1">
</div>
</form>
注意:您的<a>
标签已被submit
输入替换
如果你想通过这样做AJAX
,当上单击<a>
,然后
的HTML
<div class="head-main-recenttest-result" style="text-decoration:none;">
<a href="#">Latihan 1</a>
</div>
AJAX
$('a').click(function(){
$.ajax({
url: "bacasoal.php",
type: "post",
success:(unction(){
alert("success");
},
error:function(){
alert("error");
}
})
});
第一种方法是将页面重定向到bacasoal.php
。在第二个页面中,该页面将保留(除非您成功进入该页面)。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句