I see. PHP runs on the server and cannot directly interact with my browser,
only through Javascript. So I can use javascript to "trigger" a php script,
which does something on the server, and returns something to javascript on
my machine, which can then be used to do something on my browser.
However, as I just said in this thread, I found out that the code is
actually working, just not on my machine. I uploaded the code to a public
web server (www.bestrmvacation.com/album.htm, if you want to check it out),
and it works there. But not on my computer. There must be something broken
with my PHP or Apache Installation. However, when I run a PHP script that
calls phpinfo(), it works fine. Any idea where this might go wrong?
BTW, I am using Expression Web to develop the web site. Could that have
anything to do with it?
Thanks.
""Arno Kuhl"" <akuhl@xxxxxxxxxxxx> wrote in message
news:A6C65A0610F9485787E31F7161CB7DC3@xxxxxxxxxx
-----Original Message-----
From: mike bode [mailto:mikebode1@xxxxxxxxxxx]
Sent: 25 August 2009 07:16 AM
To: php-general@xxxxxxxxxxxxx
Subject: Beginner question
I am trying to use PHP on my web site I am developing now. I have
installed
Apache 2.2 and PHP 5.2. My problem is that I can execute PHP code embedded
in my HTML code, but I can't execute the same cose when I put it into a
separate .php file that i then call from within the html code. for
example:
I have a html file with
<body>
<?php
echo "Printing with php";
?>
<?body>
and it works fine.
When I take out the php code and put it inot a file pp.php, and I call
that
file with my browser ("localhost/pp.php"), it works, too.
But when I change the html code to:
<body>
<script type="text/javascript" src="pp.php"></script> </body>
I get a blank page. this is probably something really stupid, but I have
been wrecking my head for days now, and I can't figure it out. anybody has
an idea?
--
I presume your html/php code is in a file with a .php extension? If not
then
change the extension to "php" because most other webservers won't parse
php
code in a html file. If you have a .php file you can mix html and php the
way you described, and you can put your php code between the <?php and ?>
tags.
The php script you're trying to include in your html code with javascript
<script type="text/javascript" src="pp.php"></script>
would presumably echo out the javascript code that ends up in your html
page, but if you don't know php then you're trying to run before you can
walk.
If possible try to see what javascript code is being generated (echoed) by
the php script and put it in a normal .js file (e.g. pp.js) and then use
it
like any other javascript file
<script type="text/javascript" src="pp.js"></script>
This isn't always possible because often php is used to decide what
javascript to output (otherwise why bother). If you have to use php to
generate your javascript code then start with small steps - try echoing
some
simple js code in your pp.php (like an alert) just so you can see how it
works. Once you get that working you can move on to more useful things.
To illustrate, what's actually happening with the code you have at the
moment is this:
The browser parses the initial html code and finds
<script type="text/javascript" src="pp.php"></script>
And sends a request back to the server for pp.php
The server runs pp.php and send the output generated by the php script
back
to the browser,
so effectively the browser ends up with
<script type="text/javascript">Printing with php</script>
Obviously that isn't going to work. Hopefully you can now see what the
problem is and how to fix it.
Cheers
Arno
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php