Link to home
Start Free TrialLog in
Avatar of dplinnane
dplinnaneFlag for United States of America

asked on

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>
Avatar of psadac
psadac
Flag of France image

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');
Avatar of dplinnane

ASKER

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>
ASKER CERTIFIED SOLUTION
Avatar of psadac
psadac
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial