zoukankan      html  css  js  c++  java
  • php 数据库连接

    管理员界面:

    //用户登录界面

    <fieldset>
        <legend>用户登录</legend>
        <form action="chuli.php" method="post">
            姓名 : <input type="text" name = "uid"> <br>
            密码 : <input type="password" name= "pwd"><br>
            <input type="submit" value="登录">
        </form>
    </fieldset>

    //处理用户传过来的结果

    <?php

    //接受用户传过来的值
        $uid= $_POST["uid"];
        $pwd= $_POST["pwd"];
    //连接数据库
        $db =new MySQLi("localhost","root","","z_text");
        !mysqli_connect_error() or die("连接失败");
        $db -> query("set names utf8");

    //查询数据库中是否有对应的账号
        $sql = "select password from user where name = '$uid' ";
        $ret = $db -> query($sql);

    //将查到的值转换成数组
        $arr = $ret ->fetch_row();
        if($arr[0]==$pwd && $pwd !=null){

    //成功跳转到编辑界面
            header("location:list.php?uid=".$uid);
        }
        else{

    //不成功跳转到登录页面
            header("location:login.php?error=1");
        }
    ?>

    //编辑页面

     编辑页面

    //添加处理

    <?php
        //连接数据库
        $db =new MySQLi("localhost","root","","z_text");
        !mysqli_connect_error() or die("连接失败");
        $db -> query("set names utrf8");
        //获取用户信息
        $uid = $_POST["uid"];
        $pwd = $_POST["pwd"];
        //添加用户和密码
        $sql = "insert into  user(name,password) values('$uid','$pwd')";
        $ret = $db-> query($sql);
        //如果添加成功返回管理页面
        if($ret){
            header("location:list.php");
        }else{
            //不成功则返回添加界面并传值
            header("location:add.php?v=1");
        } 
    ?>

  • 相关阅读:
    iOS 页面之间的转场动画控制器间的转换
    C C语言中关键词,以及知识点复习
    iOS Swift基础知识代码
    LeetCode-Kth Smallest Element in a Sorted Matrix
    LeetCode-Design Phone Directory
    LeetCode-Longest Increasing Path in a Matrix
    LeetCode-Pathcing Array
    LeetCode-Wiggle Sort
    LeetCode-Odd Even Linked List
    LeetCode-Verify Preorder Serialization of a Binary Tree
  • 原文地址:https://www.cnblogs.com/plmokn/p/8422927.html
Copyright © 2011-2022 走看看