Jump to content

Impossible To Display Results Of Query


philipjordan9999

Recommended Posts

Hi,

I work in an educational establishment with a relatively small in-house IT department, and have offered to knock up a 'knowledge base' to allow them to track tickets, log solutions etc. It's not why I was hired, I'm not getting paid to do it, and frankly, if it never got done, no one's going to come down and hassle me.

 

So look on it as an education for me, I get to learn something new, and get some nice big Linux servers to play with.

 

However, I'm not going to get far, if I can't at least get the code to work. So with a copy of the famous O'Reilly book, I get to the bit where the results of a query are printed to the webpage. I've changed the code slightly to reflect my organisation's site, and of course have edited what I copy and paste here, but only to conceal certain bits that I don't want on the web.

 

 

<?php

// read in the database credentials

include('credentials.php');

// print the banner

echo ("<html><head><title>The Organisation's Knowledge Base</title></head>");

echo ("<link href=\"css/main_stylesheet.css\" rel=\"stylesheet\">");

echo ("<a href=\"http://www.our-website.com\"><img src=\"images\/logo.png\"></a>");

echo ("<hr>") ;

echo ("<h3>");

echo ("<p align=\"right\">Welcome to The Organisation's Knowledge Base");

echo ("<p align=\"left\">");

// connect to the database

$link = mysql_connect('$db_host', '$db_username', '$db_password')
or die("Connection Failed : " . mysql_error());

// select the 'knowledge' database

$db_select=mysql_select_db($db_database);
if (!$db_select) {

die ("Could not select < /br>". mysql_error) ;
}

// run the query

// first, define the variable for the query

$myQuery = "SELECT user_id,s_name,f_name,is_admin FROM users ORDER BY user_id" ;

// now run the query...

$myResult = mysql_query($myQuery);
if (!$myResult) {
die ("Could not run query... < /br>" . mysql_error()) ;
}

// loop it out

while ($result_row = mysql_fetch_row($myResult)) {
echo $result_row[2] . '<br />' ;
}

// close the link

mysql_close($link);

// close the HTML

echo ("</html>");

?>

 

The credentials file which is included, looks like this...

 

 

<?php

$db_host='localhost';
$db_database='knowledge';
$db_username='dba';
$db_password='whatthepasswordis';
?>

 

The SQL query functions flawlessly when run from within the mysql client, and four records are displayed. However, run from within a browser, it just does nothing. Not even an error message. The white background contrasts beautifully with our logo, and then the 'Welcome' message. And then.. nothing.

 

None of the above was what I thought beyond me, even if I have only been doing this for a week or so in my spare time.

 

A fresh pair of eyes would be most welcome here.

 

Thank you in advance.

post-135340-0-48948900-1356128574_thumb.png

Link to comment
Share on other sites

Do a View Source on that page. Are you sure there isn't a "Connection Failed" message? It would say something like

Connection Failed: Unknown MySQL server host '$db_host' (110)

 

The reason for that is that, if I may quote someone,

<?php echo '$single $quoted $strings $do $not $parse $variables!!!!'; ?>
Link to comment
Share on other sites

Do a View Source on that page. Are you sure there isn't a "Connection Failed" message? It would say something like

Connection Failed: Unknown MySQL server host '$db_host' (110)

 

The reason for that is that, if I may quote someone,

 

Nah, it was my stupidity. A simple sudo apt-get install php5-mysql did the job.

 

Thanks. :)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.