user5913661
user5913661

Reputation:

Laravel 5.2 Submitting Form Data

I am submitting form to /add route BUT when i click on submit button it gives this error Using : Larvel 5

{ SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '$name' for key 'name' (SQL: insert into projects (id, name, money, anything) values (, $name, 20, asfsf)) }

FORM :

{!! Form::open(array('url' => 'add')) !!}
  {!! Form::text('name', '[email protected]') !!}
  {!! Form::submit('Click Me!')!}
{!! Form::close() !!}

Routes.php

Route::post('add', function () {
   $test = Input::get('name');
   echo $test;
});

DB Snap: enter image description here

PS: I want to echo the input field value but it gives the above mentioned error.

Upvotes: 0

Views: 1101

Answers (1)

askilondz
askilondz

Reputation: 3294

You're inserting nothing for the id. notice the blank space before the comma in values (, $name, 20, asfsf)) }.

If your id field is set to auto-increment (looks like it is) then remove id from your insert statement.

insert into projects (name, money, anything) values ($name, 20, 'asfsf')

Upvotes: 1

Related Questions