0

i need to update all value into database, problem is i can't pass all value to next page for process update, my programming not strong, so what i only can think is only array.

i try to using array can get all the value within same page.

Key=56, Value=34.9 Key=57, Value=25.1 Key=58, Value=23.1 Key=59, Value=17 Key=82, Value=5 Key=4, Value=31.4 Key=5, Value=34.7 Key=7, Value=21.4 Key=84, Value=20.9 Key=10, Value=21.4 Key=11, Value=35.7 Key=13, Value=33.2 Key=39, Value=14 Key=17, Value=29 Key=2, Value=39.7 Key=28, Value=31.6 Key=73, Value=12 Key=71, Value=8 Key=70, Value=14.5 Key=72, Value=8.1 Key=49, Value=7 Key=24, Value=25.6 Key=1, Value=6.2 Key=31, Value=25 Key=74, Value=11 Key=34, Value=10.9 Key=43, Value=25 Key=67, Value=13.5 Key=80, Value=7 Key=81, Value=9 Key=22, Value=4 Key=32, Value=9.5 Key=25, Value=2 Key=88, Value=2 Key=52, Value=16.5 Key=20, Value=20.9 Key=86, Value=5

what i plan to do is when click submit button, then will update database data according ID. problem is the data is calculation result.

$next_AB = $balance + $row['replacement'] + $row['annual_day']+$sum;
$empID = $row['emp_number'];

<form action="update_entitle.php" method="GET">
<?

$data=array($empID=>$next_AB);


    foreach($data as $x=>$x_value)
     {
     echo "Key=" . $x . ", Value=" . $x_value;
     echo "<br>";
     }
}
?>


<td colspan="10">Click here to update all employee entitle leave: <input type="submit" value="Update" /></td>

$update = mysql_query("
UPDATE hs_hr_employee_leave_quota SET no_of_days_allotted = '$x_value' WHERE employee_id = '$x' AND leave_type_id =  'LTY012' AND  leave_period_id =8")or die(mysql_error());

if i update in the same page, can be update according the empID but if user refresh the page, the data will update into database too.

so what i think is send whole array to next page for process update, but i don't know how to do this.

  • Stop double post on refresh: http://stackoverflow.com/questions/7082063/double-submission-when-refresh-php – Steve Sep 18 '13 at 09:33
  • i don't really get it, can't you just post themto next page as hiddens ? – Gar Sep 18 '13 at 09:39
  • Gar, i have tried, but i only can get the last data --> Key=86, Value=5, others no display, not sure why. – user2617464 Sep 18 '13 at 09:48
  • There's quite a few things wrong with this approach. Firstly, if the form's purpose is to write non-trivial data, it should be a POST, not a GET - otherwise the `UPDATE` will try to run even if you just visit the page normally. Note you should redirect after a POST operation. Secondly, stuff like database operations shouldn't be lurking inside a `` - put it at the start of your page, or better yet in a separate file. Lastly I can't see your accessing the `$_GET` or `$_POST` but would suspect that you're not escaping, and thus may be open to SQL injection.
    – halfer Sep 18 '13 at 10:08

0 Answers0