asdflol1234
asdflol1234

Reputation: 11

Why are values not getting saved to the database?

Why are my values not getting to the database?

Let me know if more of the code is needed.

Warning:

QueryException in Connection.php line 713: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null (SQL: insert into bookmarks (name, season, episode, updated_at, created_at) values (, , , 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 Page:

@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

Upvotes: 1

Views: 72

Answers (1)

Osama Sayed
Osama Sayed

Reputation: 2023

This is how you HTML should look like :

@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

You forgot to add name attribute to your input elements

Upvotes: 2

Related Questions