Forum Moderators: coopster
I recently built a routine that takes data from a MySQL database and puts it in a drop down menu and when an item is selected it displays information relating to the item selected (also from a MySQL database).
I went back to it today only to find that Firefox (and IE) won't handle it properly. Every time a > is encountered it is treated like a ?> and instead of processing the rest of the script it displays it on the screen, thinking the php has finished.
Apache and MySQL seem to be working okay, and both Firefox and IE have trouble with it so I don't think it's an error on their part... can anybody shed any light onto how this could have happened? I've looked all over the internet but only found one solution (about short tags, which isn't the issue). The only thing I did on the PC in the meantime was install video and sound drivers and PowerDVD.
Thanks all.
However something to try would be htmlentities [uk3.php.net], as this will turn all > into > so php cant mistake that for the end of a tag...neither can the browser.
As it is possible that you have been echoing your php script into the source code of the document, but never checked to look. The > is the end of a tag so now your php is just normal CDATA and getting output to the browser.
There is definitely something fishy here. What exactly are you doing with the data from the database other than echoing it to the browser? Are you saying that ALL of the PHP script is output to the browser or just that after you echo a '>' to the browser? Are you even sure that you are processing the PHP correctly? File extensions in order? There are a lot of reasons that could cause this. Your assumption makes the least sense to me, though, so I'm thinking something else might be up.
Sorry it's taken a while for me to get back.
Basically, every single PHP script I run in a browser will start to display the code on the screen after a > if a > appears.
What I've also found today is that if a script does not contain a >, it doesn't do anything anyway.
Here's two examples from an online tutorial I used:
<?php
$numbers = array(1, 2, 3, 4, 5, 6);
$age = array("mom" => 45, "pop" => 50, "bro" => 25);
$mixed = array("hello" => "World", 2 => "It's two";
echo "numbers[4] = {$numbers[4]} <br>";
echo "My mom's age is {$age['mom']} <br>";
echo "mixed['hello'] = {$mixed['hello']} <br>";
echo "mixed[2] = {$mixed[2'}";
?>
will display:
45, "pop" => 50, "bro" => 25); $mixed = array("hello" => "World", 2 => "It's two"; echo "numbers[4] = {$numbers[4]} <br>"; echo "My mom's age is {$age['mom']} <br>"; echo "mixed['hello'] = {$mixed['hello']} <br>"; echo "mixed[2] = {$mixed[2'}"; ?>
And this:
<?php
$abc = 10; // $abc is an integer
$xyz = (boolean) $abc; // $xyz is a boolean
echo "abc is $abc and xyz is $xyz";
?>
Will display nothing.
Also, if I check the source code for a php file in IE or Firefox, it will show all the comments in the file, which I didn't think it was supposed to.
php files are saved with .php extension, but saving them with .html yields the same output.
Something fundamental seems to have broken here.
<?php
$numbers = array(1, 2, 3, 4, 5, 6);
$age = array("mom" => 45, "pop" => 50, "bro" => 25);
$mixed = array("hello" => "World", 2 => "It's two");
echo "numbers[4] = {$numbers[4]} <br>";
echo "My mom's age is {$age['mom']} <br>";
echo "mixed['hello'] = {$mixed['hello']} <br>";
echo "mixed[2] = {$mixed[2]}";
?>
<edit>
You dont have your php code within a set of <script> tags do you? This may only be a problem if you are using xhtml.
[edited by: PHP_Chimp at 6:35 pm (utc) on June 16, 2008]
So, the php code does not even seem to be being processed.
My php code is only within <?php and ?> tags.
I am guessing you are writing this code on your computer then opening up the file directly in the browser. Can you paste the address from your browser address bar? if it looks like this it won't work:
C:\path\to\script.php
the url needs to be something like this:
[domain.com...]
or if you have a webserver running on your machine this will work:
localhost://path/to/script.php
php code needs to be interpreted and processed by a web server program that is configured to run php, like apache. You either need to have server software installed on your computer or have access to a server on the internet.
Do you have access to an web server configured to run php?
If you have one running on your computer already then the problem is the path in your browser address bar. If you don't have one installed you can download and install a free one like wamp [en.wampserver.com...]
hope this helps
Yeah blots, I figured it out shortly before you posted (cheers all the same though!) - having come back to the code after a break of over a week I completely forgot to run the thing through apache. I'm not called John Doh for nothing!
Anyway, sorry it took a while to respond but been to Wales for the weekend then down to London for a few days to see Radiohead, so have been away.
Thanks all for your help, no doubt I'll be after more shortly :)