Reply to Getting results from MySQL Database in PHP

Your name:

Reply:


Posted by christopher_board on 05/11/07 21:39

Hi all. I am trying to write a php page which connects to a MySQL
Database which is supposed to get the results from a table within a
database and display the results in a table.

Below is the code that I am using:

<?php
function connectDatabase() {
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = 'password';
$db = @mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error
connecting to mysql');
echo 'connected';
$dbname = 'pmoneytest';
mysql_select_db($dbname);
}
echo '
<form action="#" method="POST" FormName="FormName">
<title>Test ResultSet Database</TITLE>
<BODY>
<B>Hello World</B><B><I> How are you today?</B></I>
</BODY>
';


connectDatabase();
echo "<table border = '1'>";
for ($x = 0; $x < $db->m_numRows; $x++) {
$row = $db->getRow();
echo
"<TR><TD>" . $row['first'] . "</td><td>";
}


?>

The problem that I am having is that it keeps on coming with the
following error and I can't find out how to fix the problem.
PHP Notice: Undefined variable: db in C:\Inetpub\wwwroot\PHPTest
\ShowDatabase.php on line 22 PHP Notice: Trying to get property of non-
object in C:\Inetpub\wwwroot\PHPTest\ShowDatabase.php on line 22.

It does say that it has connected to the MySQL Database but its the
problem with getting the results from the database.

Any help would be appreciated. Thanks very much

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация