嗨我在访问我的服务器时遇到问题我在笔记本电脑apache2和php上使用mysql。我的问题是我似乎可以连接到数据库但无法从数据库内的已注册表中获取任何数据。在此先感谢我一直在运行window7。
<?php
$username = "root";
$password = "deslap";
$hostname = "localhost";
#connection to the database seems to work and prints connected to MySQL
$dbhandle = mysql_connect($hostname, $username, $password)or die("Unable to connect to MySQL");
echo "<br />Connected to MySQL<br>";
#select a database to work with
$selected = mysql_select_db('registered',$dbhandle)or die("Could not select database");
#execute the SQL query and return records.
$result = mysql_query("SELECT id, Name FROM registered");
while($row = mysql_fetch_array($result))
{
echo "ID:".$row{'id'}." Name:".$row{'name'}."Email: ".$row{'Email'};
}
?>
</body>
</html>
答案 0 :(得分:3)
将花括号更改为方括号(您可以使用{}
或[]
,但方括号是使用数组元素的常规方法) -
echo "ID:".$row['id']." Name:".$row['Name']."Email: ".$row['Email'];
您还只选择了&#39; id&#39;和姓名(更改&#39;姓名&#39;至&#39;姓名&#39;),以便不会返回电子邮件。