用php+MySQL实现检索数据库里的内容。。。

上代码:
– 将输入的值作为模糊查询的条件:
sql="SELECTFROMtestshopWHEREgoodsnameLIKE _GET[‘uname’].”%’”;

<?php $servername = "服务器名"; $username = "账户名"; $password = "密码"; $dbname = "数据库名"; ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>搜索</title>
    <link rel = "stylesheet" type = "test/css" href = "sql_php.css"/>
</head>
<body>
    <form>
        <input type="text" id="txt_uname" name="uname"/>
            <br/>
        <input type="submit"/>
        <p>
            <?php if (isset($_GET['uname'])) { //连上数据库 $conn = new mysqli($servername, $username, $password, $dbname); if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } //查找 $sql = "SELECT * FROM test_shop WHERE goods_name LIKE '%".$_GET['uname']."%'"; //执行 $result = $conn->query($sql); //输出值 if ($result->num_rows > 0) { // 输出每行数据 while($row = $result->fetch_assoc()) { echo '<p>' . $row['goods_name'] . '</p>'; } } else { echo "没数据"; } //关闭数据库连接,释放资源 $conn->close(); } ?>
        </p>


    </form>
</body>
</html>

看看效果。。。
用php+MySQL实现检索数据库里的内容。。。_第1张图片

你可能感兴趣的:(mysql,数据库,PHP,服务器)