Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/156505-solved-need-help/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/156505-solved-need-help/#findComment-824125
Share on other sites

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( )); }

 

Link to comment
https://forums.phpfreaks.com/topic/156505-solved-need-help/#findComment-824127
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/156505-solved-need-help/#findComment-824160
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/156505-solved-need-help/#findComment-824284
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/156505-solved-need-help/#findComment-824895
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.