gpt4 book ai didi

php - 为什么值没有保存到数据库中?

转载 作者:搜寻专家 更新时间:2023-10-30 22:35:33 25 4
gpt4 key购买 nike

为什么我的值没有进入数据库?

如果需要更多代码,请告诉我。

警告:

Connection.php 第 713 行中的 QueryException:SQLSTATE[23000]:违反完整性约束:1048 列“名称”不能为空(SQL:插入书签(名称季节episode, updated_at, created_at) 值 (, , , 2016-06-19 21:44:05, 2016-06-19 21:44 :05))

Controller :

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Bookmark;
use App\Http\Requests;

class BookmarkController extends Controller
{
public function __construct() {
$this->middleware('auth');
}

public function index() {
return view('bookmarks.bookmarks');
}

public function save(Request $request) {
$bookmark = new Bookmark;
$bookmark->name = $request->name;
$bookmark->season = $request->season;
$bookmark->episode = $request->episode;

$bookmark->save();

return redirect('bookmarks');
}

public function add() {
return view('bookmarks.add');
}
}

HTML 页面:

@extends('layouts.app')

@section('content')

<div class="container">
<h1 class="text-center">Add Bookmark</h1>

<form method="post" action="{{ url('/bookmarks') }}">
{{ csrf_field() }}
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name" placeholder="Name">
</div>
<div class="form-group">
<label for="season">Season:</label>
<input type="text" class="form-control" id="season" placeholder="Season">
</div>
<div class="form-group">
<label for="episode">Episode:</label>
<input type="text" class="form-control" id="episode" placeholder="Episode">
</div>
<button type="submit" class="btn btn-primary">Add Booenter code herekmark</button>
</form>
</div>

@endsection

最佳答案

HTML 应该是这样的:

@extends('layouts.app')

@section('content')

<div class="container">
<h1 class="text-center">Add Bookmark</h1>

<form method="post" action="{{ url('/bookmarks') }}">
{{ csrf_field() }}
<div class="form-group">
<label for="name">Name:</label>
<input type="text" class="form-control" id="name" name="name" placeholder="Name">
</div>
<div class="form-group">
<label for="season">Season:</label>
<input type="text" class="form-control" id="season" name="season" placeholder="Season">
</div>
<div class="form-group">
<label for="episode">Episode:</label>
<input type="text" class="form-control" id="episode" name="episode" placeholder="Episode">
</div>
<button type="submit" class="btn btn-primary">Add Booenter code herekmark</button>
</form>
</div>

@endsection

你忘了给你的输入元素添加 name 属性

关于php - 为什么值没有保存到数据库中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37912249/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com