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
single page with referrer to show correct page
I have a simple website with a couple of different pages. I would like to be able to in a div tag w
Can't find the problem (no error message)!
OK, here's the deal. This code is really weirdly formatted (sorry!) and hard to understand, so I'm g
Where is my php.ini???
Hi
First off - apologies - i'm not a coder so this may sound very amateur.
I'm having
Hits this week counter
I have a counter on my site that tracks hits, IP's, etc. into a mySQL database. It also includes the
SHOW TABLES Help
Hi all
I have the following
Code: [Select]<?php
$sql = "SHOW TABLES&quo
PHP Redirecting
Hello everyone. Is there a way to redirect people to pages within a statement in PHP? Since there is
mysq_num_rows
Hi,
I want to use:
Code: if(mysql_num_rows($ergebnis2)==2)
how can the value 2, be
breaking a text file into paragraphs based on strings
I have a text file of email addresses that is all squished together. It looks like this:
abc
Character increment
Hi,
I am facing a scenario like above,but in my case i want to show up like Col A,Col B etc..
Target costs on Process orders not calculating
Hi All,
We have released standard costs for all the materials. We have also done Goods r