我不知道为什么我的html表单没有发送数据。我有3个名为default.php
,prosesbacasoal.php
和bacasoal.php
的文件。因为default.php太长了,所以我只想写一下我从inspect element
<form method="post" action="prosesbacasoal.php"><div class="head-main- recenttest-result">
<input type="hidden" name="nomor" value="2">
<button class="head-main-recenttest-result-wait" style="text-decoration:none;" type="submit" name="submit">2.Soal Kedua</button> </div></form>
prosesbacasoal.php
<?php
session_start();
if(isset($_POST['submit'])) {
if(isset($_POST['nomor'])) {
$_SESSION['submitsoal'] = true;
$_SESSION['nomorsoal'] = $_POST['nomor'];
header("Location:bacasoal.php");
exit;
} else {
header("Location:bacasoal.php");
exit;
}
} else {
header("Location:bacasoal.php");
exit;
}
?>
bacasoal.php也太长了所以我只写了它的一部分:
<?php
session_start();
if(isset($_SESSION['submitsoal'])) {
if(isset($_SESSION['nomorsoal'])) {
$nomorsoal = $_SESSION['nomorsoal'];
$queryjudulnya = "SELECT nomorsoal,judul,soal FROM soal WHERE nomorsoal='".$nomorsoal."'";
$runqueryjudulnya = mysqli_query($konek,$queryjudulnya);
$countqueryjudulnya = mysqli_num_rows($runqueryjudulnya);
if($countqueryjudulnya != 0) {
$assocqueryjudulnya = mysqli_fetch_assoc($runqueryjudulnya);
$juduldatabase = mysqli_real_escape_string($assocqueryjudulnya['judul']);
$soaldatabase = mysqli_real_escape_string($assocqueryjudulnya['soal']);
$nomorsoaldatabase = mysqli_real_escape_string($assocqueryjudulnya['nomorsoal']);
} else {}
} else {}
} else {}
?>
<?php
if(isset($juduldatabase) && isset($nomorsoaldatabase)) {
echo "<div class=\"head-main-recent\"> ".$nomorsoaldatabase.$juduldatabase." </div>";
} else {
echo "<div class=\"head-main-recent\">Judul soal tidak ditemukan!</div>";
}
?>
bacasoal.php
保持回显失败声明"Judul soal tidak ditemukan!"
有谁知道为什么? (现场演示:http://english-lesson.16mb.com/)
答案 0 :(得分:1)
你可以像下面这样做,这样如果有错误,那么它将显示或至少显示一些有用的信息: -
如default.php: - 的
<form method="post" action="prosesbacasoal.php">
<div class="head-main-recenttest-result">
<input type="hidden" name="nomor" value="2">
<button class="head-main-recenttest-result-wait" style="text-decoration:none;" type="submit" name="submit">2.Soal Kedua</button>
</div>
</form>
prosesbacasoal.php: - 的
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors',1);
if(isset($_POST['nomor'])) {
$_SESSION['submitsoal'] = 'true';
$_SESSION['nomorsoal'] = $_POST['nomor'];
header("location:bacasoal.php");
exit;
} else {
header("location:default.php");
exit;
}
?>
bacasoal.php: - 的
<?php
session_start();
error_reporting(E_ALL);
ini_set('display_errors',1);
$juduldatabase = '';
$soaldatabase = '';
$nomorsoaldatabase = '';
if(isset($_SESSION['submitsoal']) && isset($_SESSION['nomorsoal'])) {
$nomorsoal = $_SESSION['nomorsoal'];
$queryjudulnya = "SELECT nomorsoal,judul,soal FROM soal WHERE nomorsoal='".$nomorsoal."'";
echo $queryjudulnya;
$runqueryjudulnya = mysqli_query($konek,$queryjudulnya);
if($runqueryjudulnya){
$countqueryjudulnya = mysqli_num_rows($runqueryjudulnya);
if($countqueryjudulnya > 0) {
while($assocqueryjudulnya = mysqli_fetch_assoc($runqueryjudulnya)){
$juduldatabase = $assocqueryjudulnya['judul'];
$soaldatabase = $assocqueryjudulnya['soal'];
$nomorsoaldatabase = $assocqueryjudulnya['nomorsoal'];
}
} else {
echo "No matching record found";
}
}else{
echo "Query execution failed because of:-".mysqli_error($konek);
}
}else {
echo "Session variables are not set";
}
?>
<?php
if(isset($juduldatabase) && isset($nomorsoaldatabase)) {
echo "<div class="head-main-recent"> ".$nomorsoaldatabase.$juduldatabase."</div>";
} else {
echo "<div class="head-main-recent">Judul soal tidak ditemukan!</div>";
}
?>
注意: - 如果仍然没有错误且没有记录,那么回显查询并在db中手动运行该查询并检查是否有任何记录?
答案 1 :(得分:1)
在HTML代码的第3行,我可以在表单标记结束之前看到</div>
。我无法在表格标签
<button class="head-main-recenttest-result-wait" style="text-decoration:none;" type="submit" name="submit">2.Soal Kedua</button> </div></form>
替换为
<button class="head-main-recenttest-result-wait" style="text-decoration:none;" type="submit" name="submit">2.Soal Kedua</button></form>
答案 2 :(得分:0)
这是php会话问题,在session_destroy()之后修复了它;它使用logout.php