I have read some tutorials and videos. I just downloaded and installed laravel. Trying to create a simple registration form.
welcome.blade.php
<form action="{{URL::to('/store')}}" method="post">
{{csrf_field()}}
<input type="text" name="clientFirstname" >
<input type="text" name="clientSurname" >
<input type="text" name="clientEmail">
<input type="hidden" name="token" value="">
<button type="submit" name="button">add</button>
</form>
web.php
Route::view('/', 'welcome');
Route::post('/store', "Controller@store");
Controller.php
class Controller extends BaseController {
public function store(Request $request) {
//print_r ($request->input());
//print_r ($request->input('clientFirstname'));
$result=DB::insert("INSERT INTO test('firstname', 'surname', 'email') VALUES(?, ?, ?)", $request->input('clientFirstname'), $request->input('clientSurname'), $request->input('clientEmail'));
echo $result;
}
}
.env
DB_CONNECTION=mysql
DB_HOST=localhost
DB_PORT=3306
DB_DATABASE=testdb
DB_USERNAME=root
DB_PASSWORD=
database.php
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'port' => env('DB_PORT', '3306'),
'database' => env('DB_DATABASE', 'testdb'),
'username' => env('DB_USERNAME', 'root'),
'password' => env('DB_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => true,
'engine' => null,
],
i have created a db named testdb through phpmyadmin. Let me inform you that I can print the form fields but when i insert code as above that inser to db something i got the following error.
Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_RECOVERABLE_ERROR) Type error: Argument 1 passed to Illuminate\Database\Connection::prepareBindings() must be of the type array, string given, called in C:\Users\regor\ExampleProject\vendor\laravel\framework\src\Illuminate\Database\Connection.php on line 665
I would appreciate any help. :)