php file works fine but not when it's run from a link, why?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

php file works fine but not when it's run from a link, why?

Post by crazytopu »

i have this very simple html code stored in show.html file.

Code: Select all

a href="G:\Apache\htdocs/showdata.php">Show All Entries</a>
the showdata.php looks like this:

Code: Select all

<html>
<head><title>Show Book List in Library Stock</title></head>
<body>

<h3>List Of Available Books</h1>
<?php


$db = mysql_connect("localhost", "root");

mysql_select_db("library",$db);


$result = mysql_query("SELECT * FROM book",$db);


echo "<table border=2>\n";

echo "<tr><td>call_no</td><td>title</td><td>author1</td><td>author2</td><td>publisher</td><td>isbn</td><td>price</td><td>no_of_page</td><td>edition</td><td>category</td></tr>\n";


while ($myrow = mysql_fetch_row($result)) {



		printf("<tr><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td><td>%s</td></tr>\n",

		$myrow[0], $myrow[1], $myrow[2],$myrow[3],$myrow[4],$myrow[5], $myrow[6],$myrow[7],$myrow[8],$myrow[9]);

}

echo "</table>\n";

?>
</body>
</html>

When i click "Show All Entries" link from show.html file it gives me following output:

Code: Select all

List Of Available Books
%s%s%s%s%s%s%s%s%s%s\n", $myrow&#1111;0], $myrow&#1111;1], $myrow&#1111;2],$myrow&#1111;3],$myrow&#1111;4],$myrow&#1111;5], $myrow&#1111;6],$myrow&#1111;7],$myrow&#1111;8],$myrow&#1111;9]); &#125; echo "\n"; ?&gt;
I just do not understand how come the same showdata.php file gives me the desired output when i run it from http://localhost/showdata.php??!!!

Any clue?

[Edit: Added PHP and CODE tags for eyecandy. --JAM]
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

G:\Apache\htdocs/showdata.php
You can't do that. It's because when you call it that way, Apache or your webserver does not gets called thus PHP does not interpret it. It's either localhost or 127.0.0.1.

-Nay
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

Thanks Nay. it worked this time after i made the following change:

<a href="http://localhost/showdata.php">Show All Entries</a>
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

@ crazytopu :
Please use PHP and/or CODE tags while posting code so that the posts are easier to read.
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post by Nay »

Yep.......and read my signature for why ;)

-Nay
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post by crazytopu »

ha ha..Jam,

I was wondering whom to ask how to put the code on a white background as you people most often use in your code. But i thought that would be the most stupid question ever.

I still couldnot figure out how to do that.


P.S: you all people are amaZingly helpful. :D . Each day i am learning so much.
User avatar
JAM
DevNet Resident
Posts: 2101
Joined: Fri Aug 08, 2003 6:53 pm
Location: Sweden
Contact:

Post by JAM »

Image
Post Reply