我收到一条错误,我正在尝试理解:SQLSTATE [42S22]:未找到列:1054未知列'用户名'在' where子句' (SQL:select * from users
其中username
= hi@hi.hi limit 1)尝试登录时
我的用户'表: id email password name admin created_at updated_at 1 go@go.go $ 2y $ 10 $ 1R / 21A3C32nwkjtEgDFcyuMc2D4AtgeFnTh1ygLEcQl ... go 1 2014-11-01 21:04:33 2014-11-01 21:04:33 2 hi@hi.hi $ 2y $ 10 $ Akb9BoLWrOcQT0KFee7vvujtrzkbeRQnUDcuCXepeAd ... hi 0 2014-11-02 16:15:47 2014-11-02 16:15:47
我在视图中的表单(正确显示)
@extends('login_c')
@section('loginform')
<?= '<span style="color:red">' .
Session::get('login_error') . '</span>' ?>
{{ Form::open() }}
{{ Form::label('email', 'Email address: ') }}
{{ Form::text('email', Input::old('email')) }}
<br>
{{ Form::label('password', 'Password: ') }}
{{ Form::password('password') }}
<br>
{{ Form::submit('Login!') }}
{{ Form::close() }}
@stop
问题是我在注册之前指定了我的密码,我不明白为什么我得到&#34;无法登录&#34;或SQL注入错误。
oute::get('registration', function()
{
return View::make('registration');
});
Route::post('registration', array('before' => 'csrf',
function()
{
$rules = array(
'email' => 'required|email|unique:users',
'password' => 'required|same:password_confirm',
'name' => 'required'
);
$validation = Validator::make(Input::all(), $rules);
if ($validation->fails())
{
return Redirect::to('registration')->withErrors
($validation)->withInput();
}
$user = new User;
$user->email = Input::get('email');
$user->password = Hash::make(Input::get('password'));
$user->name = Input::get('name');
$user->admin = Input::get('admin') ? 1 : 0;
if ($user->save())
{
Auth::loginUsingId($user->id);
return Redirect::to('profile');
}
return Redirect::to('registration')->withInput();
}));
Route::get('profile', function()
{
if (Auth::check())
{
return 'Welcome! You have been authorized!';
}
else
{
return 'Please <a href="login">Login</a>';
}
});
Route::get('login', function()
{
return View::make('login');
});
Route::post('login', function()
{
$user = array(
'name' => Input::get('email'),
'password' => Input::get('password')
);
if (Auth::attempt($user))
{
return Redirect::to('profile');
}
return Redirect::to('login')->with('login_error',
'Could not log in.');
});
Route::get('secured', array('before' => 'auth', function()
{
return 'This is a secured page!';
}));
我的注册表:(抱歉,我没有发布我的完整视图,因为它不相关,我确信错误在表单和/或用户模型中。
{{ Form::open() }}
{{ Form::label('email', 'Email address: ') }}
{{ Form::text('email', Input::old('email')) }}
<br>
{{ Form::label('password', 'Password: ') }}
{{ Form::password('password') }}
<br>
{{ Form::label('password_confirm',
'Retype Password: ') }}
{{ Form::password('password_confirm') }}
<br>
{{ Form::label('name', 'Name: ') }}
{{ Form::text('name', Input::old('name')) }}
<br>
{{ Form::label('admin', 'Admin?: ') }}
{{ Form::checkbox('admin','true',
Input::old('admin')) }}
<br>
{{ Form::submit('Register!') }}
{{ Form::close() }}
@stop
我应该如何更改用户模型?为什么要保存错误的密码?
答案 0 :(得分:1)
尝试更改
$user = array(
'name' => Input::get('email'),
'password' => Input::get('password')
);
到
$user = array(
'email' => Input::get('email'), // You're using email to log in users, not name in your form
'password' => Input::get('password')
);