我想从数据库中选择数据并在我的网站上显示给登录的用户,但只有他的数据而不是其他任何人,当我把代码给出时它给出的错误通知我不知道如何解决它们请帮助我。谢谢
错误通知按摩:
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Notice: Undefined index: username in C:\xampp\htdocs\mysql_login\user_details2.php on line 20
Notice: Undefined index: name in C:\xampp\htdocs\mysql_login\user_details2.php on line 21
Username Name
这是我的PHP代码:
<?php
$con=mysqli_connect("localhost","root","123","login");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM users");
echo "<table border='1'>
<tr>
<th>Username</th>
<th>Name</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['username'] . "</td>";
echo "<td>" . $row['name'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
答案 0 :(得分:0)
尝试mysqli_fetch_assoc($ result)或mysqli_fetch_array($ result,MYSQL_ASSOC)而不是mysqli_fetch_array($ result)