zoukankan      html  css  js  c++  java
  • laravel 增删改查 数据库设置 路由设置

    laravel 框架的路由设置:          url:   http://www.shanzezhao.com/laraverl/my_laravel/public/index.php/indexs

    laravel 框架的数据库设置:config/database.php
     1  'mysql' => [
    2 'driver' => 'mysql', 3 'host' => 'localhost', 4 'port' => '3306', 5 'database' => 'laravel', 6 'username' => 'root', 7 'password' => '123456', 8 'unix_socket' => '', 9 'charset' => 'utf8', 10 'collation' => 'utf8_unicode_ci', 11 'prefix' => '', 12 'strict' => true, 13 'engine' => null, 14 ],


    laravel 框架的增删改查::

    1
    <?php 2 3 4 namespace AppHttpControllers; 5 6 use DB; 7 use AppHttpControllersController; 8 9 10 class IndexController extends Controller 11 { 12 13 //添加展示 14 public function index() 15 { 16 return view('index/index'); 17 18 } 19 //添加 20 public function add() 21 { 22 23 $name=$_POST['uname']; 24 $pwd=$_POST['upwd']; 25 // print_r($pwd);die; 26 //设置数据表
          $re=DB::table('text1')->insert(['uname'=>$name,'upwd'=>MD5($pwd)]);
    27 // print_r($re);die; 28 if($re) 29 { 30 return redirect('show'); 31 } 32 } 33 //数据展示 34 public function show() 35 { 36 $re = DB::table('text1')->get(); 37 // print_r($re);die; 38 return view('index/show',['re'=>$re]); 39 } 40 //删除 41 public function deletes() 42 { 43 $id=$_GET['id']; 44 // print_r($id);die; 45 $re= DB::table('text1') 46 ->where('id',$id) 47 ->delete(); 48 if($re) 49 { 50 return redirect('show'); 51 } 52 53 } 54 //修改页面 55 public function updates() 56 { 57 $id=$_GET['id']; 58 //print_r($id);die; 59 $re = DB::table('text1')->where('id',$id)->first(); 60 // print_r($re);die; 61 return view('index/upd',['re'=>$re]); 62 63 64 } 65 //修改 66 public function upd() 67 { 68 $name=$_POST['uname']; 69 $pwd=$_POST['upwd']; 70 $id=$_POST['id']; 71 $arr=array('id'=>$id,'uname'=>$name,'upwd'=>$pwd); 72 $re=DB::table('text1') 73 ->where('id','=',$id ) 74 ->update($arr); 75 if($re) 76 { 77 return redirect('show'); 78 } 79 80 81 } 82 83 }

     表单和以前学的框架大致还是没有什么区别的

    resources/views/index/index.blade.php

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
    <form action="add" method="post" >
        <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
        <table>
            <tr>
                <td>姓名:</td>
                <td><input type="text" name="uname"></td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input type="password" name="upwd"></td>
            </tr>
            <tr>
                <td><input type="submit" value="提交"></td>
                <td></td>
            </tr>
        </table>
    </form>
    </body>
    </html>

    show.php

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
    <center>
        <table>
            <tr>
                <td>姓名</td>
                <td>加密密码</td>
                <td>设置</td>
            </tr>
            <?php foreach ($re as $key => $val): ?>
                <tr>
    
                    <td><?php echo $val->uname; ?></td>
                    <td><?php echo $val->upwd; ?></td>
    
                    <td>
                        <a href="deletes?id=<?php echo $val->id ?>">删除</a>
                        <a href="updates?id=<?php echo $val->id ?>">修改</a>
    
                    </td>
                </tr>
            <?php endforeach ?>
    
    
    
    
    
    
        </table>
    </center>
    </body>
    </html>

    upd.php

    <!DOCTYPE html>
    <html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Document</title>
    </head>
    <body>
    <form action="upd" method="post" >
        <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
        <input type="hidden" name="id" value="<?php echo $re->id ?>">
        <table>
            <tr>
                <td>姓名:</td>
                <td><input type="text" name="uname" value="<?php echo $re->uname ?>"></td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input type="password" name="upwd" value="<?php echo $re->upwd ?>"></td>
            </tr>
            <tr>
                <td><input type="submit" value="修改"></td>
                <td></td>
            </tr>
        </table>
    </form>
    </body>
    </html
  • 相关阅读:
    HTTP协议
    idea新建工程项目结构
    idea使用的JDK版本1.9换成1.8后相关的更改设置
    Servlet
    Tomcat三种项目部署方式
    Tomcat环境变量配置命令行报错:The JRE_HOME environment variable is not defined correctl This environment variable is needed to run this program
    JDBC面试题
    XML基础入门
    数据库连接池——Druid
    $.ajax 分页
  • 原文地址:https://www.cnblogs.com/yx520zhao/p/6830753.html
Copyright © 2011-2022 走看看