|
|
|
สอบถามพี่ๆ หน่อยครับ insert ไม่ได้ แต่ตัวอื่นๆ ได้ครับ |
|
|
|
|
|
|
|
พอดีเอาสคริป ที่มี ขายทั่วไป มาปรับแต่ง ครับผม แต่ติดปัญหา ไม่สามารถ insert ได้ (ผมเพิ่มเอง)
Table ที่ไม่สามารถ เพิ่มเข้าไปได้ เป็นตัว Permissions ครับผม ผมลองแล้ว มันส่งค่าเป็น เลข 0 อะครับ
ส่วนของ Code
Code (PHP)
<?php if (!Auth::userCan('edit_users')) page_restricted();
if (empty($_GET['id']) || !is_numeric($_GET['id'])) {
redirect_to('?page=users');
}
$user = User::find($_GET['id']);
if (isset($_POST['submit']) && csrf_filter()) {
$data = array(
'email' => $_POST['email'],
'password' => $_POST['pass1'],
'password_confirmation' => $_POST['pass2'],
'role' => $_POST['role'],
'status' => $_POST['status'],
'permissions' => $_POST['permissions']
);
$rules = array(
'email' => 'required|email|max:100|unique:users,email,'.$user->id,
'password' => 'between:4,30|confirmed',
'role' => 'required',
'status' => 'required',
'permissions' => 'required',
);
if (Config::get('auth.require_username')) {
$data['username'] = $_POST['username'];
$rules['username'] = 'required|min:3|max:50|alpha_dash|unique:users,username,'.$user->id;
}
foreach (UserFields::all('admin') as $key => $field) {
if (!empty($field['validation'])) {
$data[$key] = @$_POST[$key];
$rules[$key] = $field['validation'];
}
}
$validator = Validator::make($data, $rules);
if ($validator->passes()) {
$displayName = escape(@$_POST['display_name']);
if (empty($displayName) && !empty($_POST['username'])) {
$displayName = $_POST['username'];
}
if (Config::get('auth.require_username')) {
$user->username = $_POST['username'];
}
if (!empty($_POST['pass1'])) {
$user->password = Hash::make($_POST['pass1']);
}
$user->email = $_POST['email'];
$user->display_name = $displayName;
$user->role_id = (int) $_POST['role'];
$user->status = (int) $_POST['status'];
$user->permissions = (int) $_POST['permissions'];
if ($user->save()) {
foreach (UserFields::all('admin') as $key => $field) {
Usermeta::update($user->id, $key, escape(@$_POST[$key]), @$user->usermeta[$key]);
}
redirect_to('?page=user-edit&id='.$user->id, array('user_updated' => true));
} else {
$errors = new Hazzard\Support\MessageBag(array('error' => trans('errors.dbsave')));
}
} else {
$errors = $validator->errors();
}
}
?>
รบกวนพี่ๆ หน่อยนะครับ
Tag : PHP, MySQL, HTML/CSS, JavaScript, Ajax, jQuery
|
|
|
|
|
|
Date :
2015-01-21 13:56:30 |
By :
nineaom |
View :
684 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
อาจจะต้องไปดูใน method นี้ครับ $user->save()
|
|
|
|
|
Date :
2015-01-21 20:57:53 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ได้แล้ว ครับพี่ แต่ยังเหลือ เวลาดึงมาแสดง มันไม่สามารถดึงมาได้อะครับ แต่ ส่งค่าเข้าตารางได้ T^T
ล่าสุดครับผม
Code (PHP)
<?php if (!Auth::userCan('edit_users')) page_restricted();
if (empty($_GET['id']) || !is_numeric($_GET['id'])) {
redirect_to('?page=users');
}
$user = User::find($_GET['id']);
if (isset($_POST['submit']) && csrf_filter()) {
$data = array(
'email' => $_POST['email'],
'password' => $_POST['pass1'],
'password_confirmation' => $_POST['pass2'],
'role' => $_POST['role'],
'status' => $_POST['status'],
'permissions' => $_POST['permissions'],
);
$rules = array(
'email' => 'required|email|max:100|unique:users,email,'.$user->id,
'password' => 'between:4,30|confirmed',
'role' => 'required',
'status' => 'required',
'permissions' => 'required',
);
if (Config::get('auth.require_username')) {
$data['username'] = $_POST['username'];
$rules['username'] = 'required|min:3|max:50|alpha_dash|unique:users,username,'.$user->id;
}
foreach (UserFields::all('admin') as $key => $field) {
if (!empty($field['validation'])) {
$data[$key] = @$_POST[$key];
$rules[$key] = $field['validation'];
}
}
$validator = Validator::make($data, $rules);
if ($validator->passes()) {
$displayName = escape(@$_POST['display_name']);
if (empty($displayName) && !empty($_POST['username'])) {
$displayName = $_POST['username'];
}
if (Config::get('auth.require_username')) {
$user->username = $_POST['username'];
}
if (!empty($_POST['pass1'])) {
$user->password = Hash::make($_POST['pass1']);
}
$user->email = $_POST['email'];
$user->display_name = $displayName;
$user->role_id = (int) $_POST['role'];
$user->status = (int) $_POST['status'];
$user->permissions = $_POST['permissions'];
if ($user->save()) {
foreach (UserFields::all('admin') as $key => $field) {
Usermeta::update($user->id, $key, escape(@$_POST[$key]), @$user->usermeta[$key]);
}
redirect_to('?page=user-edit&id='.$user->id, array('user_updated' => true));
} else {
$errors = new Hazzard\Support\MessageBag(array('error' => trans('errors.dbsave')));
}
} else {
$errors = $validator->errors();
}
}
?>
|
|
|
|
|
Date :
2015-02-02 15:20:46 |
By :
nineaom |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|