I need to create a system that requires the process to add, edit, delete, and view. I have some problems with editStaff.php, I can edit the data, but it does not display the data in the database when doing the process. Do you know why?

index.php

<?php
include("authenticationStaff.php");
include ("dbase.php");

        $query= "SELECT * FROM staff WHERE staff_name ='".$_SESSION['SESS_STAFF_NAME']."'";
        $result = mysql_query($query);


        $row = mysql_fetch_array($result);
        $id = $row["id"];
        $staff_id=$row["staff_id"];
        @mysql_free_result($result);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
 <html>
  <head>
    <title>SISTEM</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <meta http-equiv="content-language" content="EN" />
    <meta name="keywords" content="your,keywords,goes,here" />
    <meta name="author" content="Your Name / Original design: Majgoo" />
    <style type="text/css">@import url("style.css");</style>
 </head>

  <body>

  <div id="container">

    <div id="header" align="right">
      <h1>&nbsp;</h1>
      <p>
      <table width="490" height="20" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="255" align="left" valign="middle"><strong><font color="#000000">Welcome , You log in as </font><font color="#0000CC"> <?php echo $_SESSION['SESS_STAFF_NAME'];?></font></strong></td>
          <td width="137" align="center" valign="middle"><strong><a href="addStaff.php?id=<?php echo $staff_id; ?>" title="Add New Record"><font color="#000000">Add New Record</font></a></strong></td>
          <td width="98" align="center" valign="middle"><strong><a href="logout.php" title="Logout"><font color="#000000">Log Out</font></a></strong></td>
        </tr>
      </table>
      </p>
   </div>

   <?php
 $result= mysql_query("SELECT s.staff_name,s.staff_id,i.staff_id,i.project_name,i.location,i.cost,i.pic,i.detail,i.project_id,i.staff_name
        FROM inter1 i 
        JOIN staff s
        ON i.staff_id = s.staff_id
        WHERE s.staff_name = '".$_SESSION['SESS_STAFF_NAME']."' ") or die(mysql_error());

?>



    <h2 align="center">DATA    </h2>
    <div id="content">
    <tr>
      <td colspan="4" align="left" valign="top" class="horizon_divider">&nbsp;</td><td width="750" valign="top"><div align="center">
         <table width="830" bordercolor="#333333" border="2" align="center" style= "background-color: #FFFFFF; color: #000000; margin: 0 auto;" >
  <thead>
    <tr bgcolor="#FFFFFF">
      <th width="142" height="63">PROJECT NAME</th>
      <th width="114">LOCATON</th>
      <th width="94">COST</th>
      <th width="160">PERSON IN CHARGE</th>
      <th width="187">DETAIL</th>
      <th width="91">ACTION</th>
    </tr>
  </thead>
  <tbody>
    <?php
          while( $row = mysql_fetch_assoc( $result ) ){
            echo
            "<tr>
              <td>{$row['project_name']}</td>
              <td>{$row['location']}</td>
              <td>{$row['cost']}</td>
              <td>{$row['pic']}</td> 
              <td>{$row['detail']}</td> 

             <td><a href='editStaff.php?id={$row ['project_id']}'><font color ='blue'>EDIT</font></a>||<a href='deleteStaff.php?id={$row ['project_id']}'><font color ='blue'>DELETE</font></a></td> </tr> ";

          }
        ?>

  </tbody>
</table>
        </table>

      </div></td>
      </div>
  </div>

  </body>
</html>

editStaff.php

<?php
include("authenticationStaff.php");
include ("dbase.php");

        $query= "SELECT * FROM staff WHERE staff_name ='".$_SESSION['SESS_STAFF_NAME']."'";
        $result = mysql_query($query);


        $row = mysql_fetch_array($result);
        $id = $row["id"];
        $staff_id=$row["staff_id"];
        @mysql_free_result($result);
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
<html>
  <head>
    <title>SISTEM</title>
    <meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
    <meta http-equiv="content-language" content="EN" />
    <meta name="keywords" content="your,keywords,goes,here" />
    <meta name="author" content="Your Name / Original design: Majgoo" />
    <style type="text/css">@import url("style.css");</style>  

   </head>

  <body>

  <div id="container">

    <div id="header" align="right">
    <h1>&nbsp;</h1>
      <p>
      <table width="490" height="20" border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td width="255" align="left" valign="middle"><strong><font color="#000000">Welcome , You log in as </font><font color="#0000CC"> <?php echo $_SESSION['SESS_STAFF_NAME'];?></font></strong></td>
          <td width="137" align="center" valign="middle"><strong><a href="addStaff.php?id=<?php echo $staff_id; ?>" title="Add New Record"><font color="#000000">Add New Record</font></a></strong></td>
          <td width="98" align="center" valign="middle"><strong><a href="logout.php" title="Logout"><font color="#000000">Log Out</font></a></strong></td>
        </tr>
      </table>
      </p>
  </div>
  <?php
$idURL = $_GET['id'];
$querys ="SELECT s.staff_name,s.staff_id, i.staff_name,i.staff_id,i.project_name,i.location,i.cost,i.detail,i.pic 
FROM staff s
INNER JOIN inter1 i
 ON (s.staff_id=i.staff_id)"."WHERE s.staff_id= '$idURL' ";


$results = mysql_query($querys, $conn) or die("Could not execute query");
$rows = mysql_fetch_array($results, MYSQL_BOTH); // using numeric index or array index

    $staff_ids = $rows['staff_id'];
    $staff_name = $rows['staff_name'];
    $project_name = $rows['project_name'];
    $location = $rows['location'];
    $cost = $rows['cost'];
    $detail = $rows['detail'];
    $pic = $rows['pic'];

    @mysql_free_result ($results);
?>

    <h2 align="center">DATA</h2>
    <div id="content">
     <form action="editStaff_process.php?id=<?php echo $idURL; ?>" method="post" enctype="multipart/form-data" name="add_process" id="add_process" onSubmit="return Validate()" >
  <table width="830" height="522" bordercolor="#333333"  border="1" cellpadding="6" cellspacing="1" >
  <tr align="center" bgcolor="">
      <td   align="left"  style="padding:10px 10px 10px 10px;" >PROJECT NAME</td>
      <td  align="left"  style="padding:10px 10px 10px 10px;" >:<textarea name="project_name" cols="50" rows="2" id="project_name"  ><?php echo $project_name; ?></textarea></td>
    </tr>
    <tr align="center" bgcolor="">
     <td   align="left"  style="padding:10px 10px 10px 10px;" >LOCATION</td>
     <td  align="left"  style="padding:10px 10px 10px 10px;" >:<textarea name="location" cols="50" rows="3" id="location"><?php echo $location; ?></textarea></td></tr>
    <tr align="center" bgcolor="">
     <td   align="left"  style="padding:10px 10px 10px 10px;" >COST</td>
     <td  align="left"  style="padding:10px 10px 10px 10px;" >:<textarea name="cost" cols="50" rows="2" id="cost"><?php echo $cost; ?></textarea></td>
      </tr>
  <tr align="center" bgcolor="">
    <td   align="left"  style="padding:10px 10px 10px 10px;" >PERSON IN CHARGE</td>
    <td  align="left"  style="padding:10px 10px 10px 10px;" >:<textarea name="pic" id="pic" cols="50" rows="5" ><?php echo $pic; ?></textarea></td>
      </tr>
    <tr align="center" bgcolor="">
      <td   align="left"  style="padding:10px 10px 10px 10px;" >DETAIL ABOUT THE PROJECT</td>
      <td  align="left"  style="padding:10px 10px 10px 10px;" >:<textarea name="detail" id="detail" cols="50" rows="5"><?php echo $detail; ?></textarea></td>
      </tr>
    </table>
        <p>
        <center>
          <input class="form-submit" type="submit" name="submit" value="SUBMIT" title="Submit"/>
          <input type = "reset" value = "RESET" title="Reset" />
        </center></p></form></div>
</body>
</html>

editStaff_process.php

<?php
include("authenticationStaff.php");
include ("dbase.php");
extract( $_POST );

    $idURL = $_GET['id'];
    $project_name = $_POST['project_name'];
    $location = $_POST['location'];
    $cost= $_POST['cost'];
    $pic= $_POST['pic'];
    $detail = $_POST['detail'];

$query = "UPDATE inter1 SET project_name= '$project_name', location= '$location',cost='$cost',pic='$pic',detail='$detail' WHERE project_id = '$idURL'";



$result = mysql_query($query, $conn) or die ("Could not execute query in editStaff.php");
if ($result) {
 echo "<script type='text/javascript'> window.location='pageStaff.php'</script>";
}
?>

Recommended Answers

All 2 Replies

Hi,
Because in form definition you use method = "post" but, in your code you fetch $idURL using $_GET.
Change $idURL = $_GET['id']; with $idURL = $_POST['id']; or the form attribute method with method = "get".

Hi albucurus,
I try copy your code but still does not work.

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.