• 连接服务器一般步骤


    <?php

    编码

    header("content-type:text/html;charset=utf8");

    连接数据库

    $conn=new mysqli('localhost','root','root','服务器名字','3306');

    判断成功否

    if($conn->connect_error){

    die('连接失败'.$conn->connect_error);

    }

    读库编码

    $conn->query('set character set utf8');

    写库编码

    $conn->query('set names utf8');

    上面代码写入一个public.php文件里,用include "public.php";引入

    接收客户端信息

    $id=$_GET('id');              (id一般直接放url后面,通过get直接请求到,id设置自增的字段)

    $uname=$_REQUEST('username');

    $upwd=$_REQUEST('password');

    编写sql语句

    $sql="insert into `表名` (字段1,字段2) values ('$uname','$upwd')";

    $sql="delete form `表名` where 字段id='$id";

    $sql="update `表名` set 字段1='$uname',字段2='$upwd'  where 字段id=' $id'";

    $sql="select * from `表名` where 字段id='$id'";

    执行sql语句,曾、删、改返回值都是受影响的行数(值为0,1);查询返回值为结果集(值类似是表中所有数据的一个数组对象,只是类似)

    曾,删,改操作一样

    $res=$conn->query($sql);

    if($res){

        echo "<script>alert('注册成功');location.href='成功的页面';</script>";

    }else{

       echo "<script>alert('注册失败');location.href='失败的页面';</script>";

    }

    所以查询还要多一步,取得里面的数据

    可以先查看结果集里有多少条数据,来判断用户名存在否

    $n=mysqli_num_rows($res)

    if(!$n){

        echo "<script>alert('用户名不存在');location.href='失败的页面';</script>";

    }else{

        只能取得表中一行数据,该数据为一行表格数据的数组对象

        $row=$res->fetch_assoc();

       if($row["字段2"]==$upwd){

             echo "<script>alert('登入成功');location.href='成功的页面';</script>";

          }else{

             echo "<script>alert('密码错误');location.href='失败的页面';</script>";

           }

    }

    取得表中每行数据,该数据为表格所有数据的数组对象

    $row=$res->fetch_all();

  • 相关阅读:
    linux网络编程之共享内存介绍
    linux网络编程之system v消息队列(二)
    一次性从git远程仓库中克隆到本地。
    返回随机数:整数、浮点数
    下载进度条
    os模块学习+open行数
    json数据处理:读取文件中的json字符串,转为python字典
    python执行命令行:python中执行shell命令行read结果
    format格式化输出
    python操作mongodb
  • 原文地址:https://www.cnblogs.com/xin1021/p/9328220.html
Copyright © 2020-2023  润新知