我必须建立一个系统,系统需要添加新信息的过程。流程是添加员工携带的新信息的过程,其中所有信息,名称和员工ID将插入mysql数据库。当我尝试这个过程时,我发现staff_id
和staff_name
在数据库mysql中是空的。
这是我的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 , You log in as <?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> </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>
这是我的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>";
}
}
?>
有人可以看到我出错的地方吗?如果您需要更多信息,请告诉我。感谢。
答案 0 :(得分:0)
您需要在访问会话值的每个页面的开头使用session_start();
。