view record using id – PHP

  php

Q(Question):

i can view the list of the users but when i’m trying to view the user record using their id, the output from the database doesn’t show.

user_list.php

<?php
include 'connection.php';
$sql = "SELECT * FROM formequip, equipment, department WHERE formequip.equip_id = equipment.equip_id = department.depart_id";
$result = mysql_query($sql) or die('Query failed. ' . mysql_error());
?>
<div class="container" style="margin-top: 10px">
<table width="100%" border="0" class=" table table-striped table-bordered" id="mak_pekerja">
<thead>
<tr bgcolor="#666666">
<th width="2%" nowrap="nowrap">Bil</th>
<th width="2%" nowrap="nowrap">Jabatan</th>
<th width="14%" nowrap="nowrap">Nama</th>
<th width="7%" nowrap="nowrap">Kad Matrik</th>
<th width="9%" nowrap="nowrap">No.Telefon</th>
<th width="10%" nowrap="nowrap">Tarikh Pinjam</th>
<th width="12%" nowrap="nowrap">Tarikh Hantar</th>
<th width="15%" nowrap="nowrap">Aktiviti</th>
<th width="15%" nowrap="nowrap">Perkara</th>
<th width="15%" nowrap="nowrap">Kuantiti</th>
<th width="15%" nowrap="nowrap">Status</th>
<th width="16%" nowrap="nowrap">Tetapan</th>
</tr>
</thead>
<tbody>
<?php
$tmpCount = 1;
while ($row_lprn = mysql_fetch_assoc($result)) {?>
<tr bgcolor="#DDD">
<td><?php echo $tmpCount; ?></td>
<td><?php echo $row_lprn['department']; ?></td>
<td><?php echo $row_lprn['stud_name']; ?></td>
<td><?php echo $row_lprn['stud_id']; ?></td>
<td><?php echo $row_lprn['stud_tel']; ?></td>
<td><?php echo $row_lprn['stud_date_borrow']; ?></td>
<td><?php echo $row_lprn['stud_date_return'];?></td>
<td><?php echo $row_lprn['stud_activity']; ?></td>
<td><?php echo $row_lprn['equip_type']; ?></td>
<td><?php echo $row_lprn['stud_quantity']; ?></td>
<td><?php echo $row_lprn['stud_status']; ?></td>
<td><a href="update.php?id=<?php echo $row_lprn['id']; ?>" class="btn btn-mini btn-danger"> <i class="icon-list-alt icon-white"></i>Edit</a></td>
<td><input type="hidden" name="id" value="<?php echo $row_lprn['id']; ?>" /></td>
</tr>
<?php $tmpCount ++; }?>
</tbody>
</table>

update.php

<?php
include('connection.php');
$sql = "SELECT * FROM formequip WHERE id='".$_POST['id']."'";
$results = mysql_query($sql);
$row = mysql_fetch_array($results);
$id = $row_lprn['id'];
$stud_id = $row_lprn['stud_id'];
$equip_id = $row_lprn['equip_type'];
$stud_name = $row_lprn['stud_name'];
$stud_tel = $row_lprn['stud_tel'];
$stud_activity = $row_lprn['stud_activity'];
$stud_date_borrow = $row_lprn['stud_date_borrow'];
$stud_date_return = $row_lprn['stud_date_return'];
$equip_type = $row_lprn['equip_type'];
$stud_quantity = $row_lprn['stud_quantity'];
$id = $_POST['id'];
$submit = $_POST['submit'];
?>
<p>
<div id="form">
<form name="update" action="update2.php" method="post">
<table width="800" align="center">
<tr>
<td>No. ID</td>
<td>:</td>
<td><?php echo "$id"; ?></td>
</tr>
<tr>
<td>No. Matrik</td>
<td>:</td>
<td><?php echo "$stud_id"; ?></td>
</tr>
<tr>
<td width="173">Jabatan</td>
<td width="10">:</td>
<td width="564"><?php echo "$department"; ?></td>
</tr>
<tr>
<td>Nama Pemohon</td>
<td>:</td>
<td><?php echo "$stud_name"; ?></td>
</tr>
<tr>
<td>No. Telefon</td>
<td>:</td>
<td><?php echo "$stud_tel"; ?></td>
</tr>
<tr>
<td>Aktiviti</td>
<td>:</td>
<td><?php echo "$stud_activity"; ?></td>
</tr>
<tr>
<td>Tarikh Pinjam</td>
<td>:</td>
<td><?php echo "$stud_date_borrow"; ?></td>
</tr>
<tr>
<td>Tarikh Pulang</td>
<td>:</td>
<td><?php echo "$stud_date_return"; ?></td>
</tr>
<tr>
<td>Perkara</td>
<td>:</td>
<td><?php echo "$equip_type"; ?></td>
</tr>
<tr>
<td>Kuantiti</td>
<td>:</td>
<td><?php echo "$stud_quantity"; ?></td>
</tr>
<tr>
<td>Status</td>
<td>:</td>
<td><label>
<select name="stud_status" id="stud_status">
<option selected="selected"></option>
<option>Diluluskan</option>
<option>Tidak Diluluskan</option>
</select>
</label>
</td>
</tr>
<p align="center">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<input type="hidden" name="stud_name" value="<?php echo $stud_name; ?>">
</p>
</table><input name="submit" type="submit" id="submit" value="Kemaskini" />
</form><form action="user_list.php">
<input type="submit" value="kembali"></form>
</div>
</div>
</div>

output:

http://postimg.org/image/s00wh1iaf/

A(Answer):

in your update.php in line number 4 in your query replace the $_POST[‘id’] with $_GET[‘id’].

Read about $_GET here http://php.net/manual/en/reserved.variables.get.php

A(Answer):

i have replace it. still cant view the output :/

A(Answer):

in user_list.php for line 43 and 44, change the $row_lprn[‘id’] with $row_lprn[‘equip_id’]. I think the $row_lprn[‘id’] has no value or not existing in your tables fields.

A(Answer):

it still doesnt display the input. i try changing all the ‘POST’ to ‘GET’. the only output displayed are the id while others remain empty.

A(Answer):

Your update.php has no $row_lprn variable set anywhere.

A(Answer):

$q = isset($_GET[‘ID’]) ? $_GET[‘ID’] : ”;

$sql="SELECT ID, IC_NO, NAMA, NEGERI, Jantina FROM ahli WHERE ID= ‘".$q."’ OR NEGERI= ‘".$e."’";

mcm ini ke.

LEAVE A COMMENT