0

this is the var_dump($_POST) :

array(18) { ["_token"]=> string(40) "Qg0krYddkI2cnPQBy5T3yGJdQqRBbb9q173MXzoa" ["from_name"]=> string(2) "4r" ["from_address"]=> string(1) "4" ["invoice_id"]=> string(1) "4" ["invoice_date"]=> string(0) "" ["due_date"]=> string(0) "" ["to_name"]=> string(1) "4" ["to_address"]=> string(1) "4" ["item"]=> array(1) { [0]=> string(5) "Hours" } ["desc"]=> array(1) { [0]=> string(2) "44" } ["​unitAmt"]=> array(1) { [0]=> string(1) "4" } ["​qty"]=> array(1) { [0]=> string(1) "4" } ["​amount"]=> array(1) { [0]=> string(2) "16" } ["invoiceNotes"]=> string(2) "44" ["subTotal"]=> string(2) "16" ["total"]=> string(2) "16" ["amtPaid"]=> string(1) "0" ["balDue"]=> string(2) "16" }

As you can see the variable unitAmt is being posted, but I am getting this error when I use it :

ErrorException
Undefined index: unitAmt
open: /var/www/lk/htdocs/app/routes.php
//var_dump($rows);
//var_dump($description);


for($i=0; $i<count($rows);$i++){
    DB::table('item_description')->insert(
    array('invoice_id' => $returnID, 'item' => $rows[$i], 'description' => $description[$i],
    'unit_price' => $_POST['unitAmt'][$i], 'quantity' => $_POST['​qty'][$i], 'amount'=>$_POST['​amount'][$i]));
     }

This works fine for qty and amount which are posted similarly. Same thing is happening at other places also on dumping a variable I can see data is there but when I use it shows undefined index.

Edit : THis is my code in route.php

    var_dump($_POST);

$rows = $_POST['item'];
$description = $_POST['desc'];


 for($i=0; $i<count($rows);$i++){
    DB::table('item_description')->insert(
    array('invoice_id' => $returnID, 'item' => $rows[$i], 'description' => $description[$i],
    'unit_price' => $_POST['unitAmt'][$i], 'quantity' => $_POST['​qty'][$i], 'amount'=>$_POST['​amount'][$i]));
     }
8
  • check these three fields, your var_dump shows ? in key name, so it do not match with $_post['unitAmt'].....["?unitAmt"]=> array(1) { [0]=> string(1) "4" } ["?qty"]=> array(1) { [0]=> string(1) "4" } ["?amount"]=> array(1) { [0]=> string(2) "16" } Commented Jul 1, 2013 at 6:56
  • did not understood what you wrote. Commented Jul 1, 2013 at 6:59
  • check why "question mark" appears before unitAmt, qty and amount fields in your var_dump. Error undefined index unitAmt you are getting because of "?unitAmt" array key. Commented Jul 1, 2013 at 7:04
  • I cant see where is the question mark in ["​unitAmt"]=> array(1) { [0]=> string(1) "4" } Commented Jul 1, 2013 at 7:06
  • if "question mark" is required then add it in your $_POST['unitAmt'][$i] i.e. $_POST['?unitAmt'][$i] Commented Jul 1, 2013 at 7:06

2 Answers 2

1

Why are you using Laravel to use standard PHP functions? That kind of insertion code shouldn't be in the routes.php file, it should be in a controller or a closure. You should probably using an Eloquent model to create items. Furthermore, you can use the Input class to retrieve data that is provided by GET or POST parameters.

Sign up to request clarification or add additional context in comments.

Comments

0

I recommend you to use Eloquent model to insert an ITEM data like this way and also loop thru for all the items in your result set:-

Use input class to get POST and GET variables in laravel way

 Input::get('invoice_id') 

method get() - returns the POST and GET vars method e() - Convert HTML characters to entities and defined in laravel/helper.php

Use Eloquent to add new row in db in laravel way like:-

item_description::create($arr);

A simple example that is adding an item to item_description table in a cleaner Laravel way:-

$arr = array(
    'invoice_id' => e(Input::get('invoice_id')),
    'item' => e(Input::get('item')),
    'description' => e(Input::get('desc')),
    'unit_price' => e(Input::get('unitAmt')),
    'quantity' => e(Input::get('qty')),
    'amount' => e(Input::get('amount')),
    );   

    // Insert Data in table
    $item_description= item_description::create($arr);

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.