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
TabControl Inside ListView Not Editing
Hello everybodyI have a ListView on my page. Inside the ListView I put a TabControl, cuz I want to p
How can use this array as a key?
Say I have this array for example:
print_r($array);
Prints:
Code: [Select]Array
Pspell with my own dictionary
Hello!
I've tested two cases using pspell functions.
1)
Code: $dictionary_link = pspell_new
Validation
Hello
I know this is a really vag question.
I need to have a input field on a form th
Pop-up Banner
Hello Friends,I need to use banner in our client site.Example: www.example.com if i enter this site
1,000 select boxes with 100 options?!
I have 1 drop down select box with 1,000 options.
In some case, there will be 100+ of the
extract a file from zip file
hi,
i know how to unzip a zip file in php, but is there a way to just extract a certain file only
Help! refer to a friend script with captcha code
Hi guys, I am posting on here in desperate need for some help with an ongoing search I have been doi
download directory onto C drive
I am attempting (if this is possible) to write a routine to automatically dump the contents of a dir
Get word number x from string?
How can I use a function to loop through a string, and "have a look at" every word in the