实例
<?php /**实例 <!DOCTYPE html> <html lang="en" xmlns="http://www.w3.org/1999/html" xmlns="http://www.w3.org/1999/html"> <head> <meta charset="UTF-8"> <title>用户查询</title> </head> <body> <h2>用户查询</h2> <form action="query.php" method="post"> <label> <p>用户id:<input type="text" name="id" placeholder="请输入查询的id"></p> <p><button>提交</button></p> </label> </form> </body> </html> 运行实例 » 点击 "运行实例" 按钮查看在线实例 * Created by PhpStorm. * User: XuanGG * Date: 2018/6/3 * Time: 22:24 */ header("Content-Type: text/html; charset=UTF-8"); //创建连接参数: 因为连接参数不会经常变化,所以推荐使用常量 header("Content-Type: text/html; charset=UTF-8"); define ('DB_HOST', 'localhost'); define ('DB_USER', 'root'); define ('DB_PASS', 'root'); define ('DB_NAME', 'php'); define ('DB_CHAR', 'utf8'); $dbc = @mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME); //连接失败一定会返回错误编号,可以根据编号判断,也可用 $db是否为false进行判断 if (!mysqli_errno($dbc)) { echo '1'; }else{echo '连接失败'.mysqli_connect_error($dbc); } mysqli_select_db($dbc, DB_NAME); //选择要操作的数据库 mysqli_set_charset($dbc, DB_CHAR); //设置客户端默认字符编码集 实例 <?php /** * Created by PhpStorm. * User: XuanGG * Date: 2018/6/3 * Time: 22:38 */ header("Content-Type: text/html; charset=UTF-8"); include('conf1.php'); $id= $_POST['id']; $sql = "SELECT * FROM `USER` WHERE `user_id`={$id}"; $query =@ mysqli_query($dbc,$sql); if(mysqli_num_rows($query)==1){ echo '成功'; } ?> 运行实例 » 点击 "运行实例" 按钮查看在线实例 ?>
运行实例 »
点击 "运行实例" 按钮查看在线实例
query: