我有一个用户登录的 Intranet 站点,并显示了他负责的项目列表(这些是从数据库中提取的)-index.php
用户然后单击其中一个项目,该项目将依次显示项目需求。再次从数据库中查询。这最后一个结果实际上是由三个查询组成:第一个使用项目名称获取项目 id,第二个使用项目 id 获取需求 id,第三个使用需求 id 获取需求本身,一个字符串, 显示出来的.-project.php
需求显示在表格中,作为输入表单,更新该需求的完成状态。我有一个名为 project eval 的表,其中包含项目 ID、要求 ID 和要求完成。
我需要的是允许用户在相应的需求行中输入完整值并将其直接保存到数据库中。我的想法是使用与需求本身相关联的需求 id 来更新 fullfilment 值。
问题是我搜索了,我找不到如何...
项目 php------------------------------------------------ ----------------------------------
<?
session_start();
//Read your session (if it is set)
if (isset($_SESSION['userlogin']))
echo $_SESSION['userlogin'];
?>
<html>
<head></head>
<title>Project Requirements</title>
<body>
<div class="header"> </div>
<?php include ('Header.php') ?>
<div class="navbar"> </div>
<?php include ('NavBar.php') ?>
<div class="loggeduser">
<p align="center">
<?
if ($username = $_SESSION['username']) {
echo "Welcome $username";}
else {
echo "<a href=login.php>Please log in first</a>";
exit;
}
?>
<form action=logoff.php name=logoff>
<p align=center>
<INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Log out" style=font-weight:bolder; color:white; background-color:#990000;></form>
</p>
</div>
<div class="dbcontent">
<?
//db connection
$link = mysqli_connect('localhost', 'root','', 'qef');
// Get ProjID based on $id
$Pid =$_GET['id'];
$link = mysqli_connect('localhost', 'root','', 'qef');
//Get ProjID
$query ="SELECT ProjID FROM project WHERE ProjName='$Pid'";
$result = mysqli_query($link, $query);
// Assgn ProjID to $ProjID
(list($ProjID) = mysqli_fetch_row($result));
//Get ReqID
$query ="Select ReqID FROM projreq WHERE ProjID='$ProjID'";
$result=mysqli_query($link,$query);
//Assign ReqID to $ReqID
$ReqIDa=array ();
While ($row=mysqli_fetch_row($result)) {
array_push ($ReqIDa, $row[0]);
};
?>
<form action="rfullfilment.php" method="post">
<table border="0" cellspacing="10">
<tr>
<td align="center"><th>Project Requirements</th></td><td><th>Completion Status</th></td><td><th>Save</th></td>
</tr>
<?php
//Assign Req to $Req
foreach ($ReqIDa as $ReqID)
{
$query ="Select Req FROM requirement WHERE ReqID='$ReqID'";
$result= mysqli_query($link,$query);
$Req= mysqli_fetch_row($result);
?>
<tr>
<td align="center"><?php echo $Req[0]; ?></td><td><input type="text" name="rfullfilment" value=""></td><td ><input type="Submit" value="Save" name="Submit"></td>
<
</tr>
<?php
}
?>
</table>
</form>
</div>
<div class="footer"> </div>
<?php include ('Footer.php')?>
</body>
</html>
Rfullfilment.php
<html>
<body>
<?php
$link = mysqli_connect('localhost', 'root','', 'qef');
$Pid =$_GET['id'];
$rfullfilment = $_POST['rfullfilment'];
//Get ProjID
$query ="SELECT ProjID FROM project WHERE ProjName='$Pid'";
$result = mysqli_query($link, $query);
// Assgn ProjID to $ProjID
(list($ProjID) = mysqli_fetch_row($result));
//Get ReqID
$query ="Select ReqID FROM projreq WHERE ProjID='$ProjID'";
$result=mysqli_query($link,$query);
//Assign ReqID to $ReqID
$ReqIDa=array ();
While ($row=mysqli_fetch_row($result)) {
array_push ($ReqIDa, $row[0]);
};
foreach ($ReqIDa as $ReqID)
{
$query ="UPDATE projreq SET Rfullfilment='$rfullfilment' WHERE ReqID='$ReqID[0]'";
$result=mysqli_query($link,$query);
//$Req=mysqli_fetch_row($result);
};
//Update Rfullfilment
if(mysql_query($query)){
echo "updated";}
else{
echo "fail";};
?>
</body>
</html>