Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 305
  • Last Modified:

PHP MYSQL query results in blank page.

I created table Jokes using mysql database. Placed the jokes.php file in my /html file.
when I run in webrowser http://192.168.1.101/html/jokeslist.php
I get get a yellow background. I have tested with simple php scripts to test and they work.
However incorporating mysql nothing happens.  
Is there some configuration that is incorrect for mysql or php, how can I troubleshoot.

Here is the script.  

 <head>
<title> Our List of Jokes </title>
</head>
<body bgcolor="yellow">
<?php

  // Connect to the database server
  $dbcnx = @mysql_connect('192.168.1.101', 'root', 'xxxxxxx');
  if (!$dbcnx) {
    die( '<p>Unable to connect to the ' .
         'database server at this time.</p>' );
  }

  // Select the jokes database
  if (! @mysql_select_db('mysql.Jokes') ) {
    die( '<p>Unable to locate the joke ' .
         'database at this time.</p>' );
  }

?>
<p> Here are all the jokes in our database: </p>
<blockquote>

<?php

  // Request the text of all the jokes
  $result = @mysql_query('SELECT JokeText FROM  mysql.Jokes');
  if (!$result) {
    die('<p>Error performing query: ' . mysql_error() . '</p>');
  }

  // Display the text of each joke in a paragraph
  while ( $row = mysql_fetch_array($result) ) {
    echo('<p>' . $row['JokeText'] . '</p>');
  }

?>

</blockquote>
</body>
</html>
0
dplinnane
Asked:
dplinnane
  • 2
1 Solution
 
psadacCommented:
first, it's a very bad idea to store your tables in mysql database, use CREATE DATABASE mybase; and move your tables to this database.

second i think the problem is :

if (! @mysql_select_db('mysql.Jokes') ) {

which should be :

if (! @mysql_select_db('mysql') ) {

and :

$result = @mysql_query('SELECT JokeText FROM  mysql.Jokes');

should be :

$result = @mysql_query('SELECT JokeText FROM Jokes');
0
 
dplinnaneAuthor Commented:
I have modified code as suggested and created database test.  I still see the same result. I have tried modifying the if statements to true and false but I get no feedback "Unable to connect to the server or Cant locate database joke...."  
However when I run the same script with my webhost as opposed to my local linux box I at least get an eror message Unable to connect to the database server at this time.
This tells me there something wrong with my PHP or MYSQL setup on linux.

I am running Redhat 8 on my linux box and I cannot find file libphp4.so .

I found this information from another website.

***********************************************************Red Hat 8.0's included PHP install doesn't work with MySQL to begin with, but there are RPM modules available which can automatically configure it to work with MySQL.
***********************************************************

I will try the above first and see what happens. If you have any further input I would appreciate it.

Thanks.

<html>
<head>
<title> Our List of Jokes </title>
</head>
<body bgcolor="yellow">
<?php

  // Connect to the database server
  $dbcnx = @mysql_connect('192.168.1.101', 'root', 'lascverf');
  if (!$dbcnx) {
    die( '<p>Unable to connect to the ' .
         'database server at this time.</p>' );
  }

  // Select the jokes database
  if (! @mysql_select_db('test') ) {
    die( '<p>Unable to locate the joke ' .
         'database at this time.</p>' );
  }

?>
<p> Here are all the jokes in our database: </p>
<blockquote>

<?php

  // Request the text of all the jokes
  $result = @mysql_query('SELECT JokeText FROM Jokes');
  if (!$result) {
    die('<p>Error performing query: ' . mysql_error() . '</p>');
  }

  // Display the text of each joke in a paragraph
  while ( $row = mysql_fetch_array($result) ) {
    echo('<p>' . $row['JokeText'] . '</p>');
  }

?>

</blockquote>
</body>
</html>
0
 
psadacCommented:
i've forgotten important things, add :
error_reporting(E_ALL);
at the beginning of your script, at least during development phase.

could you verify that :
rpm -qa|grep php-mysql
returns something, if not you need to install php-mysql-XXXX.rpm
(sorry i don't use redhat so i don't know the version).

and finally one question : your webserver and database server run on the same host ?
if so use localhost instead of 192.168.1.101.

good luck :)
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now