?
Solved

PHP MYSQL query results in blank page.

Posted on 2003-03-25
3
Medium Priority
?
295 Views
Last Modified: 2013-12-12
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
Comment
Question by:dplinnane
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 14

Expert Comment

by:psadac
ID: 8209980
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
 

Author Comment

by:dplinnane
ID: 8210680
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
 
LVL 14

Accepted Solution

by:
psadac earned 375 total points
ID: 8212299
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

WordPress Tutorial 3: Plugins, Themes, and Widgets

The three most common changes you will make to your website involve the look (themes), the functionality (plugins), and modular elements (widgets).

In this article we will briefly define each again, and give you directions on how to install them.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question