我有一個表格供用戶提交他們的詢問。提交表單後,數據將轉到php文件並連接到數據庫。現在,我遇到了update.php的問題。技術上update.php會在admin.php中點擊'kemaskini'按鈕時顯示用戶個人信息的完整詳細信息。
但是這裏發生了什麼,代碼就像這樣顯示它,例如,當我點擊百合時,百合的細節就會顯示出來。但是當我點擊朱莉婭時,莉莉的細節會再次顯示。它會產生只有莉莉詳細:(
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>
在admin.php你有多種形式或它只是一個單一的形式? –
等待,問題是關於顯示,但爲什麼我在這裏看到更新。第二是因爲你再次提交表單,所以它會產生1個用戶,除非你把結果添加到你的DOM中 –
@cyberboy單我猜?實際上,admin.php是一些用戶詳細信息顯示在表中的頁面。 form.php最初是用戶提交細節的形式。 – Syaa