-2

I have to make one system where the system requires the process of adding new information. The process flow is the process of adding the new information carried by the employee where all the information, name and id of staff will insert in mysql database. When I tried the process of that, I found staff_id and staff_name was empty in database mysql.

This is my addStaff.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);
?>
<html>
<head>
<script>

function Validate()
{
    if (document.addStaff.project_name.value == '') 
    {
       alert('Please Insert Project Name!');
       document.addStaff.project_name.focus();
       return false;
    }
    if (document.addStaff.project_id.value == '') 
    {
       alert('Please Insert Project ID !');
       document.addStaff.project_id.focus();
       return false;
    }
    if (document.addStaff.location.value == '') 
    {
       alert('Please Insert Location!');
       document.addStaff.location.focus();
       return false;
    }
    if (document.addStaff.cost.value == '') 
    {
       alert('Please Insert Cost!');
       document.addStaff.cost.focus();
       return false;
    }
    if (document.addStaff.pic.value == '') 
    {
       alert('Please Insert Person In Charge!');
       document.addStaff..pic.focus();
       return false;
    }
    if (document.addStaff.detail.value == '') 
    {
       alert('Please Insert Detail about the Project!');
       document.addStaff.detail.focus();
       return false;
    }
}
</script>
</head>
<body>

<table width="869" border="0" align="center" cellpadding="0" cellspacing="0">
    <tr>
       <td width="645" height="50" align="left" valign="middle"><strong>Welcome ,&nbsp; You log in as &nbsp; &nbsp;<?php echo $_SESSION['SESS_STAFF_NAME'];?> </strong></td>
      <td width="224" align="right" valign="middle"><strong><a href="logout.html" title="Logout">Log Out</a></strong></td>
   </tr>
   </table>
   <?php
   $idURL = $_GET['id'];
   $query ="SELECT *
    FROM staff s
    JOIN inter1 i
    ON (s.staff_name=i.staff_name)";

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

    $staff_id = $row['staff_id'];
    $project_name = $row['project_name'];
    $location = $row['location'];
    $detail = $row['detail'];
    $pic = $row['pic'];
    $staff_name = $row['staff_name'];
    $project_id = $row['project_id'];


    @mysql_free_result ($result);
?>
   <center>
  <form action="addStaff_process.php?id=<?php echo $staff_id; ?>" method="post" enctype="multipart/form-data" name="add_process" id="add_process" onSubmit="return Validate()" >
  <table border="1" width="70%" cellspacing="1" cellpadding="6" >
    <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"></textarea></td>
    </tr>
     <tr align="center" bgcolor="">
      <td   align="left"  style="padding:10px 10px 10px 10px;" >PROJECT ID:</td>
      <td  align="left"  style="padding:10px 10px 10px 10px;" ><textarea name="project_id" cols="50" rows="2" id="project_id"></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="2" id="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"></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" cols="50" rows="3" id="pic"></textarea></td>
    </tr>
    <tr>
      <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" cols="50" rows="4" id="detail"></textarea></td>
    </tr>
        </table>
        <p>&nbsp;</p>
        <p>
          <input class="form-submit" type="submit" name="submit" value="SUBMIT" onClick="return Validate()"/>
          <input type = "reset" value = "RESET" />
        </p>
  </form>
</center>

</body>
</html>

And this is my addStaff_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'];
    $project_id = $_POST['project_id'];
    $staff_id = $_POST['staff_id'];
    $staff_name = $_SESSION['SESS_STAFF_NAME'];


$result ="INSERT INTO inter1 (project_name,location,cost,pic,detail,project_id)
 VALUES ('$project_name','$location','$cost','$pic','$detail','$project_id')";
$query = mysql_query ($result, $conn);

if(mysql_num_rows($query)){
 echo "<script type='text/javascript'> window.location='pageStaff.php'</script>";
}
  else{

$query1 = "UPDATE inter1 SET staff_name = '$staff_name',staff_id = '$staff_id' WHERE staff_name=$idURL";
$result1 = mysql_query ($query1, $conn);


if($result1){
 echo "<script type='text/javascript'> window.location='pageStaff.php'</script>";
    }
}
?>

Can someone see where I am going wrong?if you need any more info then please let me know. thanks.

tyra
  • 1
  • 1

1 Answers1

0

You need to use session_start(); at the start of every page that accesses the session values.

Ry-
  • 218,210
  • 55
  • 464
  • 476
ɹɐqʞɐ zoɹǝɟ
  • 4,342
  • 3
  • 22
  • 35