我正在使用我在laravel中的函数有问题,似乎是数组问题,但是由于两天了,我无法弄清楚问题是什么,错误消息是

Undefined index: eventID

我的功能

public static function DeleteRow($id){
    $data=DB::select("select * from InOutProducts where eventID=$id;");
    $eventID=$data['eventID'];
    $productID=$data['productID'];
    $username=Session::get('key');
    DB::delete("delete from InOutProducts where eventID=$eventID");
    $row=DB::select("select sum(quantity) as total_quantity from  InOutProducts  where productID='$productID' and InAndOut='1'");
    $PhysicalStock=$row[0]->total_quantity;
    DB::update("update productsStock set physicalStock=$PhysicalStock,lastUpdateBy='$username' where productID=$productID;");`

}

最佳答案

DB::select返回一个数组。尝试这个:

$data = DB::select("select * from InOutProducts where eventID=$id;");
$data = $data[0];
$eventID = $data->eventID;

关于php - Laravel未定义索引:,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/28125250/

10-12 05:39