-2

我想以表单和逐行格式显示从 mysql 检索到的值。所以我使用了以下代码。

<?php 
  while($rows1 = mysql_fetch_array($result1)){ 
?>
<tr height="30" > 
<?php $elyid = $rows1['id'] ?>
  <form action="leaveactions.php" method="post" name="viewleave">
   <td width="82"><?php echo $rows1['empid'];?></td>
   <td><?php echo $rows1['name'];?></td>
   <td><?php echo $rows1['leavetype'];?></td>
   <td width="82"><?php echo $rows1['startdate']; ?></td>
   <td width="82"><?php echo $rows1['enddate']; ?></td>
   <td><?php echo $rows1['leavetype']; ?></td>
   <td>
     <input type="submit" name="<?php $rows1['id']; ?>" value="accept"/>
   </td>
   <td>
     <input type="submit" name="reject" value="reject"/>
     <input type="hidden" name="emplid" value="<?php echo $rows1['id'] ?>"/>
   </td>
</tr>
<?php       } ?>

在 leaveactions.php 中

$ii=0;
$query1 = "select * from applied_leaves where supervisorid ='".$employeeId."' and status='not approved'";
$result1 = mysql_query($query1) or die (mysql_error());
$num1 = mysql_numrows($result1);

while($rows1 = mysql_fetch_array($result1)) {
  $ii++;
  echo $_POST["$ii"];
  if(isset($_POST['$ii'])){
    echo "accepted "; echo $_POST['$ii'];
    $updateEmp = "update applied_leaves set status='".$accept."' where id='$ii' " ;
    $uresult = mysql_query($updateEmp) or die (mysql_error());
    if($uresult != null){
      echo "Assignment Added successfully<br>";
?>
      <a href="updateassignment.php">View Added Details</a>
<?php                       
    } else {
      echo "error";
    }
  }
}
?>

但是当我跑步时

 Notice: Undefined offset: 1
 Notice: Undefined offset: 2
.
.
.
.
.
.

像那样。请帮我解决问题。提前致谢

编辑

导致异常的新代码是

                     $iii=0;
                while($rows1 = mysql_fetch_array($result1))
                {
                  $iii++;

                if(  $_POST["accpt".$iii] ) { 

                  echo "accepted "; 
                  $updateEmp = "update applied_leaves set status='".$accept."' where id='$iii' " ;
                  $uresult = mysql_query($updateEmp) or die (mysql_error());
                  if($uresult != null){
                        echo "Assignment Added successfully<br>";
                        ?>
                        <a href="updateassignment.php">View Added Details</a>
                        <?php   break;                  
                    }

                }

                }
4

2 回答 2

1

我认为您的主要错误在于:

<input type="submit" name="<?php $rows1['id']; ?>" value="accept"/>

这里你没有 echo $rows1['id'],所以如果你看一下生成的代码,名字应该是空的。

将此更正为

<input type="submit" name="<?php echo $rows1['id']; ?>" value="accept"/>

此外,leaveactions.php您还有以下代码:

// ...
echo $_POST["$ii"];
if(isset($_POST['$ii'])){
  echo "accepted "; echo $_POST['$ii'];
// ...

在这里,您应该首先检查变量(这里是$_POST[$ii]-"不需要),然后再进行输出。

由于先前的错误,$_POST[$ii]未设置,因此您首先会收到通知,之后echo再也不会输入 -if子句。

于 2013-02-11T10:44:14.613 回答
0

这是因为您尝试访问的数组位置为空(不可用)。使用isset方法检查数组位置是否存在。

if( isset( $array['position'] )
{
  //position exists
}

只是不要在这里发布您的代码。粘贴与错误相关的行。至少尝试注释发生错误的行。

于 2013-02-11T10:12:13.980 回答