Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

PolMac's avatar

Passing Data to DB

I have a Customers Table in the DB and I have a form to pass the data but I am getting an error message when I try to save from the form

(2/2) QueryException 
SQLSTATE[HY000]: General error: 1364 Field 'name' doesn't have a default value (SQL: insert into `customers` (`updated_at`, `created_at`) values (2017-08-15 21:05:01, 2017-08-15 21:05:01))
in Connection.php (line 647)
at Connection->runQueryCallback('insert into `customers` (`updated_at`, `created_at`) values (?, ?)', array('2017-08-15 21:05:01', '2017-08-15 21:05:01'), object(Closure))
in Connection.php (line 607)
at Connection->run('insert into `customers` (`updated_at`, `created_at`) values (?, ?)', array('2017-08-15 21:05:01', '2017-08-15 21:05:01'), object(Closure))
in Connection.php (line 450)
at Connection->statement('insert into `customers` (`updated_at`, `created_at`) values (?, ?)', array('2017-08-15 21:05:01', '2017-08-15 21:05:01'))
in Connection.php (line 404)
at Connection->insert('insert into `customers` (`updated_at`, `created_at`) values (?, ?)', array('2017-08-15 21:05:01', '2017-08-15 21:05:01'))
in Processor.php (line 32)
at Processor->processInsertGetId(object(Builder), 'insert into `customers` (`updated_at`, `created_at`) values (?, ?)', array('2017-08-15 21:05:01', '2017-08-15 21:05:01'), 'id')
in Builder.php (line 2139)

Controller

public function store(Request $request)
    {

        $customer = new Customer;
            array(

                'name' => Input::get('name'),
                'email' => Input::get('email'),
                'number' => Input::get('number'),
                'comments' => Input::get('comments'),
                $customer -> save());

            return \Redirect::route('booking')
                ->with('message', 'Thanks for contacting us! A member of our team will contact you to discuss your project.');
    }

Route


Route::get('booking',
    ['as' => 'booking', 'uses' => 'BookingController@create']);
Route::post('booking',
    ['as' => 'booking_store', 'uses' => 'BookingController@store']);

Form

  <h1 align="center">Contact US</h1><br><hr><br>

    <ul>
        @foreach($errors->all() as $error)
            <li>{{ $error }}</li>
        @endforeach
    </ul>

    {{Form::open(array('route' => 'booking_store', 'class' => 'form')) }}





    <div class="form-group">
        {!! Form::label('Your Name') !!}
        {!! Form::text('name', null,
            array('required',
                  'class'=>'form-control',
                  'placeholder'=>'...')) !!}
    </div>
    <br>
    <div class="form-group">
        {!! Form::label('Your E-mail Address') !!}
        {!! Form::text('email', null,
            array('required',
                  'class'=>'form-control',
                  'placeholder'=>'...')) !!}
    </div>
    <br>
    <div class="form-group">
        {!! Form::label('Your Phone Number') !!}
        {!! Form::text('number', null,
            array('required',
                  'class'=>'form-control',
                  'placeholder'=>'...')) !!}
    </div>
    <br>
    <div class="form-group">
        {!! Form::label('Comments') !!}
        {!! Form::textarea('comments', null,
            array('required',
                  'class'=>'form-control',
                  'placeholder'=>'...')) !!}
    </div>
    <br>
    <div class="form-group">
        {!! Form::submit('Contact Us!',
          array('class'=>'btn btn-primary')) !!}
    </div>


    {{ Form::close() }}

Any help would be brilliant

Pól

0 likes
4 replies
PolMac's avatar

If I change the default in the phpMyAdmin to null or as defined, a record will save but the fields are empty?

PolMac's avatar

Thank you worked perfectly

Cheers

Pól

Cronix's avatar

No problem. Mark the post as solved please.

Please or to participate in this conversation.