0

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.

10
  • This sounds more like an apache issue. Can you retrieve a simple html page? Commented May 14, 2014 at 4:50
  • Yes I have a info.php (phpinfo() ) in the same path i.e. /var/www/ which returns me the value as expected on localhost/info.php Commented May 14, 2014 at 4:52
  • 1
    the mysql_* functions are deprecated. You should look into using PDO or mysqli. I also see an error in the code that generates the table cells. echo "<td>.$result['id'].</td>"; should be echo "<td>" . $result['id'] . "</td>"; Commented May 14, 2014 at 4:56
  • This clearly doesn't seem to be programming related problem. Commented May 14, 2014 at 5:01
  • 1
    @learning, These are access logs, They only gave information about request. Their would be also error logs which would have error information. On Ubuntu their path should be /var/log/apache2/error.log Commented May 14, 2014 at 6:15

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

2 Comments

How is this different from above code? apart from assigning a variable to mysql_connect
its not just assigning the variable, Check the sixth line. It sets the current active database on the server that's associated with the specified link identifier. Please check php.net/manual/en/function.mysql-select-db.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.