POST into Array problem
Posted on
16th Feb 2014 07:03 pm by
admin
Hi Chaps,
I have a repeat region, displaying rows of data: jobid, fromtable, translatorcharge
In each row there is an input field to enter a cost for each job 'charge'.
//INPUT - TRANSLATOR CHARGE
Code: (text) <input type="text" name="translatorcharge" id="count" class="price" value="<?php echo $row_rsInvPending['jobtranslatorcharge']; ?>"/>
I have a hidden input that collects the information for each row, before sending all the information to a script page:
//HIDDEN INPUT - INFO COLLECTOR
Code: (text) <?php
$table_name = $row_rsInvPending['fromtable'];
$item_id = $row_rsInvPending['jobid'];
?>
<input type="hidden" name="jobinvsent[]" value="<?php echo $table_name; ?>:<?php echo $item_id; ?>:<?php $_POST['translatorcharge'] ?>" />
The script page then updates the translatorcharge column in the relevant table:
//SCRIPT - TO UPDATE DATABASE
Code: (text) $allowed_tables = Array('tbl_jobs','tbl_jobtransline','tbl_jobxml'); // to prevent SQL injection
foreach($_POST['jobinvsent'] as $var) {
$arr = explode(':', $var);
if(in_array($arr[0], $allowed_tables)) {
$table = $arr[0];
$rowid = $arr[1];
$transcharge = $_POST['translatorcharge'];
if(is_numeric($rowid)) {
// run your SQL query here to update $table where row matches $rowid
$mess = $ref = $_SERVER['HTTP_REFERER']; header( 'refresh: 0; url='.$ref);
$query = sprintf("UPDATE $table SET jobtranslatorcharge='$transcharge' WHERE jobid=$rowid");
$result = mysql_query($query, $conndb2) or die(mysql_error());
}
else {
$mess = "<p>There was a problem</p>";
}
}
}
The problem is, although I'm entering different values for each row, only the last entered value is being passed to the array and therefore updating all rows with the same value.
My questions is, how can I 'individualise' each input, relating to each row?
No comments posted yet
Your Answer:
Login to answer
194
50
Other forums
php ajax - two drop down list with a submit button
i have created a form with 2 drop-down list and a submit button. I would like to know how to pass th
UL and LI Add Form
The idea I want here is when the user click on a character name from the drop down select bar at the
Problems with adding a link to one position in a 'foreach' loop, please help
Hello!
Iam pretty new to programming and I wanna create a table with users from an array. It
calculator
I can't figure out why this code doesn't work. No error messages. Page loads.
Code: <
i want run some web server under the ip sharer
hello i want run some web server under the ip sharer
my ip is floating ip but it doesnt matter
Get content from table into a list, without repeating.
Alright this is kinda an odd thing, so I need some help.
I have a table "quote" wit
in php, link returns to the line
When I add a link in a php page, the link word returns to the line (as a
would do)
Examp
Help =( !! Upload Pics [PHP script]
Hello
I need help with a php script [MULTIPLE UPLOAD IMAGES] , where I want to add a feature (wat
Batch Related Pricing
Hi, I need some clarity on the batch related pricing
For example the following are the b
Deleted Delivery but material wont return
We deleted a delivery but the material its still pending.
We made a reverse goods movemen