我有一张表格供用户提交查询。提交表单后,数据将转到php文件,它将连接到数据库。现在,我有update.php的问题。技术上,当在admin.php中单击“kemaskini”按钮时,update.php将显示有关其ID的用户个人信息的完整详细信息。
但是这里发生了什么,代码显示如下,例如,当我点击Lily时,会显示Lily详细信息。但是当我点击Julia时,Lily会再次显示细节。它只生产百合细节:(
admin.php的
<tr>
<th>NO</th>
<th>NAMA PEMOHON</th>
<th>UNIT/JABATAN/ <br>BAHAGIAN</th>
<th>NO.TELEFON</th>
<th>E-MAIL</th>
<th>DATA/LAPORAN YANG DIPOHON</th>
<th>TUJUAN</th>
<th>TINDAKAN</th>
<th>AGIHAN</th>
<th>KEMASKINI</th>
</tr>
<tbody>
<?php
include('config.php');
$bil = 0;
//$option = '';
$results = mysql_query("SELECT * FROM pemohon");
//$option .='<select>';
//$count=mysql_num_rows($results);
//
while ($row = mysql_fetch_array($results, MYSQL_ASSOC))
{
$bil++;
echo "<form name='update $bil' action=update.php method=post>"; ?>
<tr>
<td><center><?php echo $bil; ?></center></td>
<td><?php echo $row['name']; ?></td>
<td><?php echo $row['unit']; ?></td>
<td><?php echo $row['telefon']; ?></td>
<td><?php echo $row['email']; ?></td>
<td><?php echo $row['data']; ?></td>
<td><?php echo $row['tujuan']; ?></td>
<td><?php echo $row['tindakan']; ?></td>
<td><?php echo $row['agihan']; ?></td>
<td><input type='submit' name='submit' value='kemaskini'>
<input type='hidden' name='id' value=<?php echo $row['id']; ?></td>
</tr>
<?php
}
?>
update.php
<?php
include('config.php');
$sql = "SELECT * FROM pemohon WHERE id='".$_POST['id']."'";
$results = mysql_query($sql);
$row = mysql_fetch_array($results);
//$user = $row['username'];
$id = $row['id'];
$name = $row['name'];
$jawatan = $row['jawatan'];
$unit = $row['unit'];
$kementerian = $row['kementerian'];
$telefon = $row['telefon'];
$faks = $row['faks'];
$email = $row['email'];
$data = $row['data'];
$tujuan = $row['tujuan'];
$tarikh = $row['tarikh'];
$tindakan = $row['tindakan'];
$id = $_POST['id'];
$submit = $_POST['submit'];
?>
<form name="update" action="update2.php" method="post">
<table width="763" align="center">
<tr>
<td>No. ID</td>
<td>:</td>
<td><?php echo "$id"; ?></td>
</tr>
<tr>
<td width="173">Nama Pemohon</td>
<td width="10">:</td>
<td width="564"><?php echo "$name"; ?></td>
</tr>
<tr>
<td>Jawatan</td>
<td>:</td>
<td><?php echo "$jawatan"; ?></td>
</tr>
<tr>
<td>Unit/Jabatan/Bahagian</td>
<td>:</td>
<td><?php echo "$unit"; ?></td>
</tr>
<tr>
<td>Kementerian/Institusi/Agensi</td>
<td>:</td>
<td><?php echo "$jawatan"; ?></td>
</tr>
<tr>
<td>No. Telefon</td>
<td>:</td>
<td><?php echo "$telefon"; ?></td>
</tr>
<tr>
<td>No. Faks</td>
<td>:</td>
<td><?php echo "$faks"; ?></td>
</tr>
<tr>
<td>E-mail</td>
<td>:</td>
<td><?php echo "$email"; ?></td>
</tr>
<tr>
<td>Data/Laporan Yang Dipohon</td>
<td>:</td>
<td><?php echo "$data"; ?></td>
</tr>
<tr>
<td>Tujuan</td>
<td>:</td>
<td><?php echo "$tujuan"; ?></td>
</tr>
<tr>
<td>Tarikh Permohonan</td>
<td>:</td>
<td><?php echo "$tarikh"; ?></td>
</tr>
<tr>
<td>Tindakan</td>
<td>:</td>
<td><label>
<select name="tindakan" id="tindakan">
<option selected="selected"></option>
<option>Diluluskan</option>
<option>Tidak Diluluskan</option>
</select>
</label>
</tr>
<tr>
<td>Agihan</td>
<td>:</td>
<td><label>
<select name="agihan" id="agihan">
<option selected="selected"></option>
<option>Pn. Suryana Binti Embong</option>
<option>Pn. Rohaida Binti Ali</option>
<option>En. Hasril Rezuan Bin Suboh</option>
</select>
</label>
</tr>
<p align="center">
<input type="hidden" name="noid" value="<?php echo $id; ?>">
<input type="hidden" name="name" value="<?php echo $name; ?>">
<input name="submit" type="submit" id="submit" value="Kemaskini" />
</p>
</form>
答案 0 :(得分:1)
在admin.php中,您错过了结束“&gt;”在INPUT标签中。
<input type='hidden' name='id' value=<?php echo $row['id']; ?>
应该是
<input type='hidden' name='id' value="<?php echo $row['id']; ?>">
所以隐藏的输入没有被关闭,不是由浏览器发送的,所以$ _POST ['id']是空的,这就是为什么你一直得到带有空id的相同记录的原因。
好的做法是始终使用“”作为值。有了它们,您将清楚地看到标签是否已关闭,您将避免使用带空格的值的问题。