manddox Posted May 2, 2009 Share Posted May 2, 2009 Hi all, I am new to php and trying to learn from scratch. I installed everything using Xampp. I have been following this book('Learning php and mysql by Oreilly.2nd edition') but got stuck at this stage where am unable to query the Database with PHP Functions. I got evrything right but when i view the file db_test.php file in browser i get nothing but the following code: // Include our login information include('db_login.php'); // Connect $connection = mysql_connect($db_host, $db_username, $db_password); if (!$connection){ die ("Could not connect to the database: <br />". mysql_error( )); } The above code is part of my db_test.php file which is saved in htdocs folder. The file has the following codes: <?php // Include our login information include('db_login.php'); // Connect $connection = mysql_connect($db_host, $db_username, $db_password); if (!$connection){ die ("Could not connect to the database: <br />". mysql_error( )); } // Select the database $db_select=mysql_select_db($db_database); if (!$db_select){ die ("Could not select the database: <br />". mysql_error( )); } // Assign the query $query = "SELECT * FROM books NATURAL JOIN authors"; // Execute the query $result = mysql_query( $query ); if (!$result){ die ("Could not query the database: <br />". mysql_error( )); } // Fetch and display the results while ($result_row = mysql_fetch_row(($result))){ echo 'Title: '.$result_row[1] . '<br />'; echo 'Author: '.$result_row[4] . '<br /> '; echo 'Pages: '.$result_row[2] . '<br /><br />'; } //Close the connection mysql_close($connection); ?> I have checked evrything and followed all right and now cannot make any clue where is it going wrong or is the file saved in the wrong directory or something else. Plz help or give some hint for further troubleshooting! Quote Link to comment https://forums.phpfreaks.com/topic/156505-solved-need-help/ Share on other sites More sharing options...
wildteen88 Posted May 2, 2009 Share Posted May 2, 2009 What have you saved the file as. Make sure you have saved it with a .php file extension, eg filename.php. By default PHP is only parsed within .php files. The file should also be placed within XAMPP's htdocs folder (eg C:/xampp/htdocs) You should also be going to http://localhost to run your .php files. Quote Link to comment https://forums.phpfreaks.com/topic/156505-solved-need-help/#findComment-824125 Share on other sites More sharing options...
manddox Posted May 2, 2009 Author Share Posted May 2, 2009 hello wildteen88, Yes, I have saved the file with php extension only and under the htdocs folder (D:/program files/xampp/htdocs/) along with my db_login.php file which has the database login settings. I am also running the file under http://localhost/db_test.php and receive the same result i.e the following code comes up in my browser: // Include our login information include('db_login.php'); // Connect $connection = mysql_connect($db_host, $db_username, $db_password); if (!$connection){ die ("Could not connect to the database: ". mysql_error( )); } Quote Link to comment https://forums.phpfreaks.com/topic/156505-solved-need-help/#findComment-824127 Share on other sites More sharing options...
wildteen88 Posted May 2, 2009 Share Posted May 2, 2009 What editor are using to create the file with? Quote Link to comment https://forums.phpfreaks.com/topic/156505-solved-need-help/#findComment-824129 Share on other sites More sharing options...
manddox Posted May 2, 2009 Author Share Posted May 2, 2009 I am using Adobe Dreamweaver cs3 to edit the files! Quote Link to comment https://forums.phpfreaks.com/topic/156505-solved-need-help/#findComment-824156 Share on other sites More sharing options...
the182guy Posted May 2, 2009 Share Posted May 2, 2009 If the file extension is .php and the code begins with <?php and ends with ?> then it means PHP is either not installed or not correctly installed/configured, or not enabled on your machine. Here is a tutorial for installing PHP, MySQL and Apache on a development machine, without using any nasty all in one installers. Quote Link to comment https://forums.phpfreaks.com/topic/156505-solved-need-help/#findComment-824160 Share on other sites More sharing options...
manddox Posted May 2, 2009 Author Share Posted May 2, 2009 I don't understand. Xampp is supposed to do all the installation and configuration. SO, why do i need to go thru the process of installing and configuring again?....can somebody put some more light on this issue before i install again(if really i have to do this again)! Thanks in advance. Quote Link to comment https://forums.phpfreaks.com/topic/156505-solved-need-help/#findComment-824284 Share on other sites More sharing options...
manddox Posted May 3, 2009 Author Share Posted May 3, 2009 hi @wildteen, @the182guy, I uninstalled xampp and dreamweaver and then reinstalled again...and it seems to have done the trick..still don knw wat was actually the issue when I tried to display the data from the databases previously. This time it worked fine and am able to display the data from my database. Thanks wildteen and the182guy for all ur help. Quote Link to comment https://forums.phpfreaks.com/topic/156505-solved-need-help/#findComment-824895 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.