sql:
-- phpMyAdmin SQL Dump -- version 4.5.1 -- http://www.phpmyadmin.net -- -- Host: 127.0.0.1 -- Generation Time: 2022-04-05 10:24:07 -- 服务器版本: 10.1.13-MariaDB -- PHP Version: 5.6.21 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO"; SET time_zone = "+00:00"; /*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; /*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; /*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; /*!40101 SET NAMES utf8mb4 */; -- -- Database: `a` -- -- -------------------------------------------------------- -- -- 表的结构 `login` -- CREATE TABLE `login` ( `id` int(11) NOT NULL, `username` varchar(100) COLLATE utf8_vietnamese_ci NOT NULL COMMENT '用户名', `password` varchar(100) COLLATE utf8_vietnamese_ci NOT NULL COMMENT '密码' ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_vietnamese_ci; -- -- 转存表中的数据 `login` -- INSERT INTO `login` (`id`, `username`, `password`) VALUES (50, 'cyg', '123456'), (51, 'admin', '123456'), (52, 'admin', '123456'), (53, 'admin', '123456'), (54, 'admin', '123456'), (55, 'admin', '123456666'); -- -- Indexes for dumped tables -- -- -- Indexes for table `login` -- ALTER TABLE `login` ADD PRIMARY KEY (`id`); -- -- 在导出的表使用AUTO_INCREMENT -- -- -- 使用表AUTO_INCREMENT `login` -- ALTER TABLE `login` MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=56; /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
<?php $link=mysqli_connect('localhost','root','','a'); //然后是指定php链接数据库的字符集 mysqli_set_charset($link,'utf8'); if(!$_POST['username']||!$_POST['password']) { exit(); } $username=$_POST['username']; $password=$_POST['password']; $sql = "INSERT INTO login(username,password) VALUES ('{$username}','{$password}')"; $result=mysqli_query($link,$sql);//运行sql if($result) { $sql="select * from login where username='$username' and password='$password'"; $result=mysqli_query($link,$sql);//运行sql } if(mysqli_num_rows($result) > 0){ while($row = mysqli_fetch_assoc($result)) { $data[] = $row; } $json = json_encode(array( "resultCode"=>200, "message"=>"新增成功!", "data"=>$data ),JSON_UNESCAPED_UNICODE); //转换成字符串JSON echo($json); }else{ $json = json_encode(array( "resultCode"=>200, "message"=>"暂无数据", "data"=>'' ),JSON_UNESCAPED_UNICODE); //转换成字符串JSON echo($json); } ?>