我创建了一个网站,它有多个登录和独特的信息..我想从一个用户检索数据。例如我的用户名是qwert,我的密码是1234,我想将他的唯一信息检索到数据库。我在w3schools中使用了示例代码,它选择了所有数据,但我想要做的就是从用户那里检索数据,只能登录。
任何人都可以帮我这个吗?任何帮助将不胜感激。
mysql_select_db("xone_login", $con);
$result = mysql_query("SELECT * FROM admin WHERE username = '$myusername' ");
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['overtime'] . "</td>";
echo "<td>" . $row['daily_rate'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysql_close($con);
?>
答案 0 :(得分:2)
用这个替换该教程中SQL中的代码(并调整表名和列名):
SELECT * FROM USERS where name ='qwert' and pass = MD5('1234')
并注意清理变量以避免SQL注入攻击!
答案 1 :(得分:-1)
You need to use a where clause
Also you will need to specify limits on the query to restrict the result set to 1 record
$select = "SELECT * FROM usertable WHERE username = '$user' LIMIT 0, 1";
$query = mysql_query($select) or die(mysql_error());
$result = mysql_fetch_assoc($query);
//Prints the array
print_r($result);