Blogger Information
Blog 70
fans 4
comment 5
visits 103778
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
PHP:【ThinkPHP】=> 通用后台管理,用户名,头像,判断是否为空
JiaJieChen
Original
978 people have browsed it

PHP:【ThinkPHP】=> 通用后台管理,用户名,头像,判断是否为空

HTML 代码块

       
  1. //图片上传 js方法
  2. functionsave(){
  3. $.post("{$config['admin_route']}Jz/user_add",$('form').serialize(),function(res){
  4. switch(res.id){
  5. case0:
  6. layer.msg(res.msg,{'icon':2});
  7. break;
  8. case1:
  9. layer.msg(res.msg,{'icon':1});
  10. setTimeout(function(){parent.window.location.reload();},1000);
  11. break;
  12. case2:
  13. layer.msg(res.msg,{'icon':2});
  14. break;
  15. default:
  16. layer.msg(res.msg,{'icon':2});
  17. break;
  18. }
  19. },'json');
  20. }

PHP 代码块

       
  1. publicfunctionuser_add()
  2. {
  3. //用户添加
  4. //判断是否是post 提交 是的话再输出
  5. if(Request::isPost()){
  6. $name=Request::post('name');
  7. $img=Request::post('test_img');
  8. //判断名称和头像是否为空
  9. if(empty($name)||empty($img)){
  10. echo json_encode(['id'=>2,'msg'=>'名称和图片不能为空']);
  11. return;//结束判断
  12. }else{
  13. //执行数据插入数据库
  14. $insert=Db::table('xmjz_user')->insert([
  15. 'name'=>$name,
  16. 'img'=>$img,
  17. 'status'=>1
  18. ]);
  19. }
  20. //判断是否插入成功,数据返回给前端
  21. if(!empty($insert)){
  22. echo json_encode(['id'=>1,'msg'=>'成功']);
  23. }else{
  24. echo json_encode(['id'=>0,'msg'=>'失败']);
  25. }
  26. }else{
  27. returnView::fetch();
  28. }
  29. }
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply withNews Comment Service Agreement
0 comments
Author's latest blog post
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!