您好我已经开发了一个php页面。现在的问题是我想根据id只显示mysql表中的一行。下面是代码:
会话部分
<?php
session_start();
if(!isset($_SESSION['id_g'])){
echo '<script>window.alert("Please log in to use this system.");window.location=("../psm/index3.php");</script>';
}
else {
include "../psm/conn.php";
$id_g = $_SESSION['id_g'];
$query = "SELECT * FROM guru WHERE id_g = '$id_g' ";
$hasil = $conn->query($query);
$cetak = $hasil->fetch_assoc();
extract($cetak);
}
?>
显示表部分
<form action="review-outing.php" method="post">
<table style="border-color: #000000;">
<tbody>
<?php
$sql = " SELECT id_s, fullname_s, nric_s, hostel_s, dorm_s, class_s, id_kb, sebab_kb, tarikh_kb, status_kb, nota_kb FROM pelajar INNER JOIN keluarbandar USING (nric_s) WHERE nric_s='$nric_s'";
$verifikasi = $conn->query($sql);
$hitung = $verifikasi->num_rows;
if($hitung){
while($cetak=$verifikasi->fetch_assoc()){
extract($cetak);
echo '
<div class="table-wrapper">
<table class="alt">
<tbody>
<tr>
<td style="width: 150px;">ID Permohonan</td>
<td>'.$id_kb.'</td>
</tr>
<tr>
<td style="width: 150px;">Nama Pelajar</td>
<td>'.$fullname_s.'</td>
</tr>
<tr>
<td>No. KP Pelajar</td>
<td><input type="number" name="nric_s" value="'.$nric_s.'" readonly /></td>
</tr>
<tr>
<td>Hostel</td>
<td>'.$hostel_s.'</td>
</tr>
<tr>
<td>Dormitori</td>
<td>'.$dorm_s.'</td>
</tr>
<tr>
<td>Kelas</td>
<td>'.$class_s.'</td>
</tr>
<tr>
<td>Tarikh Keluar ke Bandar</td>
<td>'.$tarikh_kb.'</td>
</tr>
<tr>
<td>Sebab Memohon untuk Keluar ke Bandar</td>
<td style="text-align: justify;"> '.$sebab_kb.'</td>
</tr>
<tr>
<td>Status</td>
<td><input type="radio" name="status_kb" value="Diluluskan">Diluluskan
<input type="radio" name="status_kb" value="Ditolak">Ditolak</td>
</tr>
<tr>
<td>Catatan</td>
<td>Sedikit ulasan atau komen guru..<br>
<input type="text" name="nota_kb" placeholder="'.$nota_kb.'" row="2" required></td>
</tr>
</tbody>
</table>
<br>
<input type="submit" name="update1" value="Kemaskini Permohonan">
</div>
';
}
}
else{
echo "Tiada permohonan keluar ke bandar diterima.";
}
?>
</form>
出现错误如下;
Notice: Undefined variable: nric_s in C:\xampp\htdocs\PSM\reviewouting.php on line 134
Tiada permohonan keluar ke bandar diterima.
如果我在查询中删除了WHERE nric_s ='$ nric_s'部分,它将显示mysql表中的所有行。
答案 0 :(得分:-1)
$ nric_s没有初始值。你必须初始化什么是$ nric_s值。
例如
$ nric_s = $ _ POST [&#39; nameOfInput&#39;];