运行MySQL查询的PHP页面

运行MySQL查询的PHP页面,php,html,mysql,Php,Html,Mysql,我需要一个PHP+HTML页面,它会要求用户输入两个值,即密码和id_类别 到目前为止,我已经将PHP编码为: <?php $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "db1"; // Create connection $conn = new mysqli($servername, $username, $password, $dbname); // Che

我需要一个PHP+HTML页面,它会要求用户输入两个值,即密码和id_类别

到目前为止,我已经将PHP编码为:

<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "db1";


// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}

$sql = "select user_id,mobile from test_user_table where id_category like '912' or id_category like '912%' or id_category like '%912%' or id_category like '%912'";
$result = $conn->query($sql);

if ($result->num_rows > 0) {
    // output data of each row
    while($row = $result->fetch_assoc()) {
        echo "id: " . $row["user_id"]. " - Mobile: " . $row["mobile"]. "<br>";
    }
} else {
    echo "0 results";
}
$conn->close();
?>

您的
html
将如下所示

<!DOCTYPE html>
<html>
<title>Login Form</title>
<body>
    <form action="form_submit" method="post">
        <table>
            <tr>
                <td>Username</td>
                <td>:</td>
                <td><input type="text" name="username" /></td>
            </tr>
            <tr>
                <td>Password</td>
                <td>:</td>
                <td><input type="password" name="username" /></td>
            </tr>
            <tr>
                <td>Category</td>
                <td>:</td>
                <td><select name="category">
                        <option value="192">Category 1</option>
                        <option value="193">Category 2</option>
                        <option value="194">Category 3</option>
                        <option value="195">Category 4</option>
                    </select></td>
            </tr>
        </table>
    </form>
</body>
</html>
这将有助于:

HTML:

<form name="login" method="post">
Username<input type="text" name="username"/>
Password<input type="password" name="password"/>
Category<input type="text" name="category"/>
<input type="submit" name="submit"/>
</form>
<?
if (isset ($_POST["submit"]){
$username = mysqli_real_escape_string( $_POST["username"]);
$password = mysqli_real_escape_string( $_POST["password"]);
$category = mysqli_real_escape_string( $_POST["category"]);


// YOUR QUERY
$sql = "
SELECT columns FROM table WHERE 
username = '$username' AND
password = '$password' AND (
categoryid LIKE '$category' OR 
categoryid LIKE '%$category' ....
)

 ";

}//if end
    ?> 

用户名
密码
类别
PHP:

<form name="login" method="post">
Username<input type="text" name="username"/>
Password<input type="password" name="password"/>
Category<input type="text" name="category"/>
<input type="submit" name="submit"/>
</form>
<?
if (isset ($_POST["submit"]){
$username = mysqli_real_escape_string( $_POST["username"]);
$password = mysqli_real_escape_string( $_POST["password"]);
$category = mysqli_real_escape_string( $_POST["category"]);


// YOUR QUERY
$sql = "
SELECT columns FROM table WHERE 
username = '$username' AND
password = '$password' AND (
categoryid LIKE '$category' OR 
categoryid LIKE '%$category' ....
)

 ";

}//if end
    ?> 

使用三个输入字段生成表单,并使用$\u POST或get或request@devpro我是这方面的初学者。你能告诉我怎么做吗?给你寄一个样品试试这个你检查过了吗finding@devpro仍在寻找。可能会要求某人为我编写页面代码。我需要两个不同的文件,还是也可以在一个文件中?你可以在同一个文件中使用它。你可以分享我的建议,我如何改进?