我创建了一个登录表单和一个处理sql连接的连接页面。每次打印“未检索到查询”。我想使用文本框中提供的登录详细信息运行查询。如果为true,则必须将名字存储在会话中。
这是我用来将其与php链接的数据库结构
数据库z1760359
表成员
member ID firstName lastName userName password
index.php
<html>
<head>
<style>
#login
{
position:absolute;
top: 30%;
bottom: 30%;
left:30%;
right:30%;
margin: 0px auto;
}
</style>
</head>
<body>
<?php
session_start();
echo"<center>";
echo"<div id=\"login\">";
echo"<form method=\"POST\" action=\"connectivity.php\">";
echo"<b>Username</b> <input type =\"text\" name=\"username\">";
echo"<br/><br/>";
echo"<b>Password</b> <input type =\"password\" name=\"password\">";
echo"<br/><br/>";
echo"<input type=\"submit\" value=\"submit\">";
echo"</div>";
echo"</center>";
?>
</body>
</html>
Connectivity.php
<?php
$username = $_POST['username'];
$password = $_POST['password'];
$host="localhost";
$uname="root";
$pword="";
$db="z1760359";
$conn=mysqli_connect($host,$uname,$pword,$db) or die("Oops something went wrong");
session_start();
$query="Select firstName from member where userName=$username, password=$password";
if(!empty($_POST['username']))
{
$query_first=mysqli_query($conn,$query) or die(" Query not retrieved");
$query_second=mysqli_fetch_assoc($query_first);
if(!empty($row['username']) AND !empty($row['password']) )
{
$_SESSION['user_name']=extract($query_second);
}
else
{
echo"wrong password";
}
}
else
{
echo"please enter the password or username";
}
echo"$password";
echo"<br>";
echo"$username";
?>
最佳答案
如果不使用准备好的语句,则必须在mysql中的值周围加上单引号:
$query="Select firstName from member where userName='$username' AND password='$password'";
同样,您必须在条件之间使用逻辑运算符。
关于php - PHP没有从MySQL获取数据,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/29766551/