php adding to post issue

4 replies
Here is the code i have right now. im not sure what im doing wrong. ive tryed a few different things and can not seem to get it working.

what i need to do is add a new line to the array at the end of the array.

$invoice_number = $_POST['invoice'];
$invoice_shipping_query = tep_db_query("SELECT value FROM orders_total WHERE orders_id = '" . $invoice_number . "' and class = 'ot_shipping'");
$invoice_shipping = tep_db_fetch_array($invoice_shipping_query);
$shipping_cost = $invoice_shipping['value'];
$arrayPost = array_push_assoc($arrayPost, 'shipping', $shipping_cost);

any help would be appriciated
#adding #issue #php #post
  • maybe ....

    foreach ($_POST as $k=>$v){$posted[$k] = $v;}

    $invoice_number = $posted['invoice'];

    $invoice_shipping_query = tep_db_query("SELECT value FROM orders_total WHERE orders_id = '" . $invoice_number . "' and class = 'ot_shipping'");
    $invoice_shipping = tep_db_fetch_array($invoice_shipping_query);
    $shipping_cost = $invoice_shipping['value'];

    $posted['shipping'] = $shipping_cost;
    {{ DiscussionBoard.errors[3623306].message }}
  • Profile picture of the author layouts4you
    that was a great try. didnt work.
    {{ DiscussionBoard.errors[3623526].message }}
  • Profile picture of the author phpbbxpert
    First does array_push_assoc() function exist? Its not a built in PHP function.

    You could just use PHP's array_push()
    array_push( $shipping_cost, 'shipping');

    print_r( $shipping_cost);

    Will now have shipping added to the array.

    NOTE: do not assign array_push to a var, its a converter and the assigned var will output a count not the array.

    To push key => value you would need a function something like this.
    function array_push_assoc($array, $key, $value){
    $array[$key] = $value;
    return $array;
    }

    This pushes the keys also.
    But the function you are using is using different params
    In which your first param should result in an undefined variable.
    So I am not sure what you are trying to do there.
    {{ DiscussionBoard.errors[3623867].message }}
  • Profile picture of the author theofficialSJ
    Now is it working fine?. Let us know
    {{ DiscussionBoard.errors[3625258].message }}

Trending Topics