[英]Server error while trying to display data from mysql db in php
I have a database, db_db which I want to display data from in my browser. 我有一个数据库db_db,它想在浏览器中显示数据。 I have put this php code (display.php) under /var/www/ and trying to access
localhost/display.php
. 我已将此php代码(display.php)放在/ var / www /下,并尝试访问
localhost/display.php
。 Though everytime I come across "Server Error" The website encountered an error while retrieving http://localhost/display.php
. 虽然每次遇到“服务器错误”,但网站在检索
http://localhost/display.php
时都遇到错误。 It may be down for maintenance or configured incorrectly. 可能由于维护原因而停机或配置不正确。
The code is below: 代码如下:
<?php
//make conn
$link = mysql_connect('localhost', 'root', '');
//select db
mysql_select_db('db_db') or die( "Unable to select db");
$sql = "SELECT * FROM results WHERE jobid = 'abc'";
$records = mysql_query($sql);
?>
<html>
<head>
<title> Result Info </title>
</head>
<body>
<table width="600" border = "1" cellpadding = "1" cellspacing= "1">
<tr>
<th>id</th>
<th>name</th>
<tr>
<?php
while($result = mysql_fetch_assoc($records)){
echo "<tr>";
echo "<td>.$result['id'].</td>";
echo "<td>.$result['name'].</td>";
echo "</tr>";
}//end while
?>
</table>
</body>
</html>
Not sure where am I going wrong. 不知道我要去哪里错了。
There might be the problem with your database select and query syntax. 您的数据库选择和查询语法可能存在问题。 Modify your code
修改你的代码
<?php
//make conn
$link = mysql_connect('localhost', 'root', '');
//select db
mysql_select_db('db_db', $link) or die( "Unable to select db");
$sql = "SELECT * FROM results WHERE jobid = 'abc'";
records = mysql_query($sql);
?>
Check if it works. 检查它是否有效。 Good luck
祝好运
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.