I want to display values retrieved from mysql in forms and in row by row format.
So i used the following code.
<?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 } ?>
and in 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";
}
}
}
?>
but when run i get
Notice: Undefined offset: 1
Notice: Undefined offset: 2
.
.
.
.
.
.
like that.
Please help me solving the problem.
Thanks in Advance
EDIT
the new code that is causing exception is
$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;
}
}
}
I think your main error lies here:
Here you do not echo
$rows1['id'], so if you have a look in the generated code, the name should be empty.Correct this to
Furthermore in
leaveactions.phpyou have the following code:Here you should first check, whether the variable (here it is
$_POST[$ii]– no"needed) before doing the output.As a result of the previous error,
$_POST[$ii]is not set, thus you get the notice on the firstechoand never enter theif-clause afterward.