doutuo3899 2015-08-20 04:40
浏览 27

多个mysql行条目没有明显的原因(偶尔会发生一次)

I have the following code for store() in my controller. Although the awkward delete was added later to get rid of the problem, it did not work.

public function store()
{
    $input = \Input::all();
    $userdetail = \Auth::User();

    foreach($input['user_id'] as $user_id) {
        \StudentAttendance::where('academicsession_id', '=', $input['academicsession_id'])
            ->where('class_id', '=', $input['class_id'])
            ->where('section_id', '=', $input['section_id'])
            ->where('attendance_on', '=', $input['attendance_on'])
            ->where('user_id', '=', $user_id)
            ->delete();
        $obj = new \StudentAttendance();
        $obj->academicsession_id = $input['academicsession_id'];
        $obj->class_id = $input['class_id'];
        $obj->section_id = $input['section_id'];
        $obj->user_id = $user_id;
        $obj->attendance_on = $input['attendance_on'];

        $obj->is_present = (isset($input['is_present'][$user_id])) ? 1 : 0;
        $obj->addBy = $userdetail['id'];
        $obj->status_id = 1;
        $obj->save();
    }

    return \Redirect::to('teachers/attendance')->with('status_success', trans('msg.success_attendance_saved'));
}

The problem is, every once in a while, for no apparent reason, I get duplicate entries in my db with same created_at and updated_at timestamps.

Please follow the link to see the screenshot (http://i.imgur.com/WGciSVW.jpg?1)

Not really sure what might be causing it to happen. Any help is appreciated. Thanks

  • 写回答

1条回答 默认 最新

  • dpp80346 2015-08-20 04:52
    关注

    Disable/Hide the submit button once it is clicked may be due to frequent clicks it cause this error.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度