Hi,
I am now try to fixing the error in my update form but I still cannot find where is it.
Can anyone help me with this problem?
There is no error occur but the form cannot update to database and also appear the blank form.
These are my code for update.
update_staff.php
<head>
<script src="datetimepicker_css.js"></script>
</head>
<?php
$con = mysql_connect("localhost","root","root");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("pqs", $con);
$ref1 = $_REQUEST['ref1'];
$result = mysql_query("SELECT Staff_name, Staff_id_no, Staff_jawatan, Staff_dept, Staff_purpose, staff_date, Staff_time_in, Staff_Time_out FROM staffdb WHERE Staff_id = '$ref1' LIMIT 0,1");
?>
<script type="text/javascript">
function show_alert()
{
var msg = "Successful : Your data saved";
alert(msg);
}
</script>
<form name="form1" method="post" action="update_staff1.php">
<p> </p>
<table width="476" border="0" align="center">
<tr>
<th colspan="3" scope="col"><div align="center">Rekod Staff Masuk Selepas Waktu Bekerja </div>
<div align="left"></div></th>
</tr>
<?php while($row = mysql_fetch_array($result))
{
?>
<input type="hidden" name="Staff_id" value="<?php echo $ref1; ?>" />
<tr>
<th width="150" scope="row"><div align="right">Nama</div></th>
<td width="5"><div align="center"><strong>:</strong></div></td>
<td width="299"><div align="left">
<input name="Staff_name" type="text" id="Staff_name" value="<?php echo $row['Staff_name'];?>" size="40">
</div></td>
</tr>
<tr>
<th scope="row"><div align="right">No. Pass </div></th>
<td><div align="center"><strong>:</strong></div></td>
<td><div align="left">
<input name="Staff_id_no" type="text" id="Staff_id_no" value="<?php echo $row['Staff_id_no'];?>" size="40">
</div></td>
</tr>
<tr>
<th scope="row"><div align="right">Jawatan</div></th>
<td><div align="center"><strong>:</strong></div></td>
<td><div align="left">
<input name="Staff_jawatan" type="text" id="Staff_jawatan" value="<?php echo $row['Staff_jawatan'];?>" size="40">
</div></td>
</tr>
<tr>
<th scope="row"><div align="right">Jabatan</div></th>
<td><div align="center"><strong>:</strong></div></td>
<td><div align="left">
<input name="Staff_dept" type="text" id="Staff_dept" value="<?php echo $row['Staff_dept'];?>" size="40">
</div></td>
</tr>
<tr>
<th scope="row"><div align="right">Tujuan</div></th>
<td><div align="center"><strong>:</strong></div></td>
<td><div align="left">
<textarea name="Staff_purpose" cols="40" id="Staff_purpose"><?php echo $row['Staff_purpose'];?></textarea>
</div></td>
</tr>
<tr>
<th scope="row"><div align="right">Tarikh</div></th>
<td><div align="center"><strong>:</strong></div></td>
<td><div align="left">
<input name="staff_date" type="text" id="staff_date" value="<?php echo $row['staff_date'];?>" />
<img src="../images/cal.gif" width="16" height="16" style="cursor:pointer" title="Click on the calendar to enter date" onclick="javascript:NewCssCal('staff_date','yyyymmdd','arrow')"/> </div></td>
</tr>
<tr>
<th scope="row"><div align="right">Masa masuk </div></th>
<td><div align="center"><strong>:</strong></div></td>
<td><div align="left">
<input name="Staff_time_in" type="text" id="Staff_time_in" value="<?php echo $row['Staff_time_in'];?>" />
<a href="javascript:NewCssCal('Staff_time_in','24','true of false','arrow')" title="Click on the calendar to enter date"> <img src="../images/cal.gif" width="16" height="16" alt="Pick a time" /></a> </div></td>
</tr>
<tr>
<th scope="row"><div align="right">
<div align="right">Masa keluar </div>
</div></th>
<td><div align="center"><strong>:</strong></div></td>
<td><div align="left">
<input name="Staff_Time_out" type="text" id="Staff_Time_out" value="<?php echo $row['Staff_Time_out'];?>" />
<a href="javascript:NewCssCal('Staff_Time_out','24','true of false','arrow')" title="Click on the calendar to enter date"> <img src="../images/cal.gif" width="16" height="16" alt="Pick a time" /></a> </div></td>
</tr>
<?php }?>
<tr>
<th colspan="3" scope="row"><div align="right"></div>
<div align="center"></div>
<div align="left"></div></th>
</tr>
<tr>
<th colspan="3" scope="row"> <div align="center">
<input name="update" type="submit" id="update" value="Update" onclick="show_alert()"/>
<input name="back" type="submit" id="back" value="Back"/>
</div>
<div align="center"></div>
<div align="left"></div></th>
</tr>
</table>
<?php
mysql_close($con);
?>
</form>
update_staff1.php
<?php
if (isset($_POST['submit'])){
$link = mysql_connect("localhost","root","root") or die ("Could not connect to the Database Server!");
$db = mysql_select_db("pqs", $link) or die ("Could not select Database!");
$Staff_id = $_POST['Staff_id'];
$Staff_id_no = $_POST['Staff_id_no'];
$Staff_name = $_POST['Staff_name'];
$Staff_purpose = $_POST['Staff_purpose'];
$Staff_time_in = $_POST['Staff_time_in'];
$Staff_Time_out = $_POST['Staff_Time_out'];
$Staff_dept = $_POST['Staff_dept'];
$Staff_jawatan = $_POST['Staff_jawatan'];
$staff_date = $_POST['staff_date'];
$result=mysql_query("UPDATE staffdb SET Staff_id_no = '$Staff_id_no', Staff_name = '$Staff_name', Staff_purpose = '$Staff_purpose', Staff_time_in = '$Staff_time_in', Staff_Time_out = '$Staff_Time_out', Staff_dept = '$Staff_dept', Staff_jawatan = '$Staff_jawatan', staff_date = '$staff_date' WHERE Staff_id = '$Staff_id'");
mysql_close($link);
}
if($result){
echo "<script type='text/javascript'>window.location='index.php?page=list_staff.php'</script>";
}
?>
Thanks in advance everyone!