-2

any help you offer on this will be useful. Am working on my school project and this error code keeps popping up on the application "Undefined index: client_id" on line 1001"

Here is the code

public function onNewclientaddress(){
    $addShipmentForm  = Settings::get('addShipmentForm',true);
    $data = post();

      = \Spot\Shipment\Models\Address::where('user_id', $data['client_id'])->update(['default' => 0]);

    if ( $addShipmentForm == "add_form_normal"){
        $subitem = new \Spot\Shipment\Models\Address;
        $subitem->name              = htmlspecialchars($data['street_addr']);
        $subitem->user_id           = htmlspecialchars($data['client_id']);
        $subitem->street            = htmlspecialchars($data['street_addr']);
        $subitem->city              = htmlspecialchars($data['city_id']);
        $subitem->zipcode           = htmlspecialchars($data['postal_code']);
        $subitem->country            = htmlspecialchars($data['country_id']);
        $subitem->default           = 1;
        $subitem->created_at        = \Carbon\Carbon::now();
        $subitem->updated_at        = \Carbon\Carbon::now();
        $subitem->save();
    }
    else{

       

line 1001 is the first line of code in the post. please pardon my English

  • this simpy means that there is no `client_id` in your data. What happens if you `dd($data)` ? – Aless55 Aug 17 '20 at 12:39
  • 2
    (FYI, the code you have _currently_ shown will never show that error, it won’t get that far - because it contains a parse error.) – CBroe Aug 17 '20 at 12:43

1 Answers1

-1

This error indicates that $data['client_id'] is not being set. You will need to ensure that whatever form is providing this data, is passing client_id correctly.

You can see what is currently in $data with a line like:

die(var_dump($data));

This will output the data on the page.

Ensure your client_id field in your form has a name attribute:

name="client_id"
Peter B
  • 437
  • 4
  • 14