如何从给定输入的sql行打印特定信息?

时间:2017-01-12 16:44:29

标签: php mysql

这是我的SQL查询:

$sql = "SELECT username, password, am, email, age, sex, country, city FROM personal_details where username='username_' and password='$password_'";

变量$ username_和$ password_取自HTML表单。我想要做的是打印这些值的所有信息(用户名,密码,上午,电子邮件,年龄,性别,国家,城市),如果没有,则打印"给定输入没有记录&#34 ;

完整代码:

$username_ = $_POST["username"];
$password_ = $_POST["password"];

mysqli_set_charset($conn, "utf8");

$sql = "SELECT username, password, am, email, age, sex, country, city FROM personal_details WHERE username='username_' AND password='$password_'";

$result = mysqli_query($conn, $sql);

if (!$result) {
    echo "Could not successfully run query ($sql) from DB: " . mysql_error();
    exit;
}

if (mysql_num_rows($result) == 0) {
    echo "No rows found, nothing to print so am exiting";
    exit;
}

while ($row = mysql_fetch_assoc($result)) {
    echo $row["username"];
    echo $row["password"];
}


mysqli_close($conn);

我得到的错误:

  

警告:mysql_num_rows()期望   参数1是资源,给定的对象   第27行的C:\ xampp \ htdocs \ register \ view.php没有找到任何行,没有找到任何行   打印所以即将退出

0 个答案:

没有答案