-1

i tried to send the variable of $sum into another like this one in my time.php

session_start();
while($row = mysql_fetch_array($result))
{
$num++;
$sum += $row['totalmin'];
echo "<tr>";
echo "<td><center>".$row['timein']."</center></td>"; 
echo "<td><center>".$row['timeout']."</center></td>"; 
echo "<td><center>".$row['totalmin']."</center></td>";
echo "</tr>";
}

if($num==15){
    echo "<tr>";
    echo  "<td>";
    echo  "<td>totaltime";
    echo "<td><center> ".$sum."</center></td>";
    echo "</td>";
    echo "</td>";
    echo "</tr>";
}
$_SESSION['sum'] = $sum;
echo "<td><a href= \"salary.php?id=".$mytime_id." \">salary";

into this

salary.php

<?php
include 'dbconfig.php';
session_start();
$id = $_GET['id'];
$sql = "SELECT * FROM income WHERE id = $id";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$sum = $_SESSION['sum'];
?>

<html>
<head>
<title></title>
</head>
<body>
<form method="POST" action="salary_edit.php">
record to edit<br/>
<input type="hidden" name="id" value="<?php echo $id;?>" readonly="readonly"/><br/>
Salary :<input type="text" name="salary" value="<?php echo $sum; ?>"/><br/>
deductions:<input type="text" name="deductions" value="<?php echo $row['deductions'] ?>"/><br/>

<input type="submit" name="save" value="SAVE"><br/>
</form>

<a href="view2.php<?php echo '?id='.$id;?>">back </a><br/>
</body>
</html>
<?php
mysql_close();
?>

but i got an Notice: Undefined index: sum in this line $sum = $_SESSION['sum'];

is their anyway to get the $sum in time.php into salary.php beside $_SESSION or make the $sum into a $_POST?

user3793272
  • 111
  • 8

2 Answers2

0

You have to use session_start in both scripts, not only in the second one.

blue112
  • 52,634
  • 3
  • 45
  • 54
0

put session_start() at top of the first file.

session_start();
while($row = mysql_fetch_array($result))
{
  //rest of code
Kylie
  • 11,421
  • 11
  • 47
  • 78