SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    POST into Array problem

    Hi Chaps,

    I have a repeat region, displaying rows of data:
    jobid
    fromtable
    charge

    In each row there is an input field to enter a cost for each job 'charge'.
    HTML Code:
    <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:
    PHP Code:
    <?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:
    PHP Code:
    $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?

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    name="translatorcharge"
    change this to
    name="translatorcharge[]"

  3. #3
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi hash, thanks for the reply, I did what you said but all the values now say 'Array' instead of the value I entered.
    This is what was posted by the script page:
    Array ( [translatorcharge] => Array ( [0] => [1] => 10 [2] => 20 [3] => 30 [4] => 40 ) [jobinvsent] => Array ( [0] => :: [1] => tbl_jobxml:86: [2] => tbl_jobxml:69: [3] => tbl_jobs:145: [4] => tbl_jobs:144: ) )

  4. #4
    SitePoint Wizard
    Join Date
    Nov 2005
    Posts
    1,191
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I'm not quite sure what you are doing with the hidden input field that collects the information - input fields can't really do that - but best guess (as in the problem is you only get the last input field in your form processing script) is that you need to use array syntax for "translatorcharge"

  5. #5
    SitePoint Addict
    Join Date
    Aug 2009
    Posts
    299
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, thanks for that, if I use array syntax for 'translatorcharge' how would I then update 'translatorcharge' value to the corresponding 'jobinvsent' array?
    eg:
    [translatorcharge]
    [0] =>
    [1] => 10
    [2] => 20

    [jobinvsent]
    [0] =>
    [1] => tbl_jobs:184
    [2] => tbl_jobxml:144

    Well, I'm not quite sure what you are doing with the hidden input field that collects the information - input fields can't really do that
    I was told (from another forum) that this would do the trick, as the data is being pulled from 3 tables, and repeated in a dynamic table. So I have a hidden input that collects the information (for each row) loops through the Query, then passes the info to the script, which updates each value in the array with the entered value for that particular row...(which is what I'm having problems with)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •