I have a database, db_db which I want to display data from in my browser. I have put this php code (display.php) under /var/www/ and trying to access localhost/display.php
. Though everytime I come across "Server Error" The website encountered an error while retrieving 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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.