Page 1 of 1

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

Posted: Sun Jan 04, 2004 11:00 am
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]

Posted: Sun Jan 04, 2004 11:02 am
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

Posted: Sun Jan 04, 2004 11:12 am
by crazytopu
Thanks Nay. it worked this time after i made the following change:

<a href="http://localhost/showdata.php">Show All Entries</a>

Posted: Sun Jan 04, 2004 11:15 am
by JAM
@ crazytopu :
Please use PHP and/or CODE tags while posting code so that the posts are easier to read.

Posted: Sun Jan 04, 2004 11:17 am
by Nay
Yep.......and read my signature for why ;)

-Nay

Posted: Sun Jan 04, 2004 11:23 am
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.

Posted: Sun Jan 04, 2004 11:31 am
by JAM
Image