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>&nbsp;</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!

Hi,

You dont seem to have a variable $row which is what you have used as the values in your textboxes.

<input name="Staff_name" type="text" id="Staff_name" value="<?php echo $row['Staff_name'];?>" size="40">

Replace this code

<?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");?>

with this code

<?php$con = mysql_connect("localhost","root","root");if (!$con)  {  
die('Could not connect: ' . mysql_error());  } 
mysql_select_db("pqs", $con);$ref1 = $_REQUEST['ref1'];
$sql = "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";
if ($result=mysql_query($sql)){
while ($row=mysql_fetch_assoc($result))
{?>

Hi,

You dont seem to have a variable $row which is what you have used as the values in your textboxes.

<input name="Staff_name" type="text" id="Staff_name" value="<?php echo $row['Staff_name'];?>" size="40">

Replace this code

<?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");?>

with this code

<?php$con = mysql_connect("localhost","root","root");if (!$con)  {  
die('Could not connect: ' . mysql_error());  } 
mysql_select_db("pqs", $con);$ref1 = $_REQUEST['ref1'];
$sql = "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";
if ($result=mysql_query($sql)){
while ($row=mysql_fetch_assoc($result))
{?>

Its not working..
Can you explain it more detail?

hey mate,

forget what i said before because i read over it again and the while loop is actually there i just missed it.

I think the bit on update_staff1.php which is

if (isset($_POST['submit'])){

is the part that checks the form has been submitted and if it has it will continue. But it gets the from the input name in the submit button on the previous page and you have 2 submit buttons and neither of them are named submit.
At the bottom of update_staff.php you have

<input name="update" type="submit" id="update" value="Update" onclick="show_alert()"/>
<input name="back" type="submit" id="back" value="Back"/>

so try changing the start of update_staff1.php from
if (isset($_POST
to
if (isset($_POST

Hi,
I know you have not asked this but mysql_** is depricating and you are advised to move to mysqli or the PDO. I suggest PDO due to portability and easy. If you know OOP it is extremely easy. you can use this as skeleton to get started with PDO. Copy test and play around to fit your needs

<html>
<head>

</head>
<body>
<?php
    ini_set("display_errors", 1);//error mgt
    try{
        $db = new PDO("mysql:host=localhost;dbname=test", "root", "root");
    }catch(PDOException $e){        
        echo $e->getMessage();
    }
    
    $stmt=$db->prepare("INSERT INTO likesys(liked) VALUES(:like)");
    $stmt2=$db->prepare("SELECT SUM(liked) AS likes FROM likesys WHERE liked=:like");
    $display=false;
    if(isset($_POST["like"])){
        $stmt->execute(array(":like"=>"1")); 
        $display=true;
    }
    if(isset($_POST["dislike"])){
        $stmt->execute(array(":like"=>"-1")); 
        $display=true;
    }
    $stmt->closeCursor();
    
    //if($display){ 
        $stmt2->execute(array(":like"=>"1"));
        $res = $stmt2->fetch(PDO::FETCH_ASSOC);  
        echo "<p>Likes: ". $res['likes']."</p>";
        
        $stmt2->execute(array(":like"=>"-1"));
        $res = $stmt2->fetch(PDO::FETCH_ASSOC);  
        echo "<p>Dislikes: ". abs($res['likes'])."</p>";
   // }
    
    $db=null;
?>
    <form action=<?php echo $_SERVER["PHP_SELF"];?> method="POST" >
        <input name="like" type="submit" value="Like" />
        <input name="dislike" type="submit" value="Dislike" />
    </form>
</body>
</html>

Agree with Mathieu. you have no Post var coming from the form called 'submit'. Change the if statement at the top of your update processing page. I would suggest using this instead of the isset() that you have there now...

if ($_POST['update']=="Update"){
   //the update code... 
}

This would allow you to have this page potentially handle additional updates. Furthermore it requires the user to have clicked the button labeled "Update". The way you had it if someone clicked a button that happened to be called update just to get to the page, the script to run the update would have been triggered.

Thanks evstevemd and ajbest!
I really don't realize that the submit command.
Pity me..
Thanks so much for both of you.. :)

Thanks evstevemd and ajbest!
I really don't realize that the submit command.
Pity me..
Thanks so much for both of you.. :)

you are welcome!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.