0

我有一个用户登录的 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>
4

1 回答 1

0

您正在fulfillment.php 中查找$_GET['id'],但您没有将其与project.php 上的表单一起发送

您应该将表单操作更改为

<form action="rfullfilment.php?id=<?php echo $Pid; ?>" method="post">

或者添加一个隐藏的表单域来传输数据。

<input type=hidden name=id value=<?php echo $Pid; ?>>

然后更改$_GET['id'] to $_POST['id']您的fulfillment.php 代码。

我不确定这是否能回答你的问题,最后一点对我来说有点困惑。

于 2013-06-07T12:03:16.523 回答