Forum Moderators: coopster

Message Too Old, No Replies

php mistakes greater than symbol for ?>

php mistakes greater than symbol for?>

         

johndoh

1:50 pm on Jun 11, 2008 (gmt 0)

10+ Year Member



Hi there,

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.

PHP_Chimp

9:06 pm on Jun 11, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you are getting php code on the generated html page then the problem is with something in php. As the browser has no control over what is sent to it.
So there is something in your script that is wrong.

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.

eelixduppy

1:14 am on Jun 12, 2008 (gmt 0)



Welcome to WebmasterWorld, Johndoh!

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.

johndoh

12:59 pm on Jun 16, 2008 (gmt 0)

10+ Year Member



Hi there,

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_Chimp

6:33 pm on Jun 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




<?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]}";
?>

There were a few mistakes in the first set of code. Try the above.

<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]

johndoh

1:52 pm on Jun 18, 2008 (gmt 0)

10+ Year Member



Cheers for the new set of code, but that's not the issue. In fact, it helps illustrate the problem. The tutorial that the code was taken from does contain many errors, I assume to acquiant people better with the language by making them solve them. However, using either version still gives the same result. The first set should have thrown a load of error messages on the screen, but it did not - it just displayed what I showed before.

So, the php code does not even seem to be being processed.

My php code is only within <?php and ?> tags.

eelixduppy

2:19 pm on Jun 18, 2008 (gmt 0)



The only thing I can think of is you don't have PHP properly installed on your computer and all of the tags, including the opening and closing PHP tags, are being interpreted as HTML tags and that's why they aren't "showing up". I bet if you were to look at the source code you'd see that the whole script is there. Make sure that your installation [us2.php.net] is correct, then restart your server for the changes to take effect.

johndoh

2:14 pm on Jun 19, 2008 (gmt 0)

10+ Year Member



Yeah, you do see the whole script there. I'll have a look at php, but can anybody explain to me why it would do this without me touching it?

blots

7:47 pm on Jun 19, 2008 (gmt 0)

10+ Year Member



your code is not being processed by php. the browser is seeing the "<" in <php as the beginning of a html tag. then the first ">" as the end of the tag. So "<?php" is not being recognized at all.

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

johndoh

6:40 pm on Jun 27, 2008 (gmt 0)

10+ Year Member



Hi there,

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 :)