Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

I've created LAMP server in my ubuntu desktop. I've also made a sample database in Mysql having 6 columns. I can access it through the terminal. I've also created a php script for accessing the same. But when I'm not able to run it in the web browser....

It just shows me a blank page....and nothing else !!!!

Below is my code:

// I'd typed http://_MY_IP_ADDRESS_/_FILE_NAME_.php in the browser to run this file

<?php

include('db_login.php');            // include the login info of the user
$connection = mysql_connect($db_host, $db_username, $db_password); // make the connection

if( !$connection )
{
    die("Couldn't connect to the database: <br />", mysql_error());
}    

$db_select = mysql_select_db($db_database);// select the database

if( !$db_select )
{
    die("Couldn't select the database: <br />", mysql_error());
}

// developing the query

$select = 'select';
$coloumn = ' * ';
$from = 'from';
$table = 'table';

$query = $select.$coloumn.$from.$table;                     
$result = mysql_query($query);                          

if( !$query )
{
    die("Couldn't query the database: <br />", mysql_error());
} 

// fetching and displaying the result

while($result_row = mysql_fetch_row($result))
{
    echo "A".$result_row[1]."<br />";
echo "B".$result_row[2]."<br />";
echo "C".$result_row[3]."<br />";
echo "D".$result_row[4]."<br />";
echo "E".$result_row[5]."<br />";
echo "F".$result_row[6]. "<br /><br />";
}

mysql_close($connection);   
// closing the connection

?>
share|improve this question

1 Answer 1

Syntax problems on line 8:

die("Couldn't connect to the database: <br />", mysql_error());

. is used as concatenation, not ,

Same problem on line 15 and 30.

Also, turn on error reporting. To do so:

ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);

This will turn on all errors.

share|improve this answer
1  
Also, the query results will start at $result_row[0] not $result_row[1] and end at $result_row[5] –  douggro Jan 28 at 19:04
    
Thanks Flukey and douggro for your quick responses....!!!! They solved everything. –  dhruvil25 Feb 6 at 15:54

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.