php page displaying text that is supposed to be part of php code
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
As a side-note I am running apache-2.2.9 on a Slackware 12.1 box. All my other PHP files work perfect, it is just this one that isn't working properly.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
I tried it on my own server after editing a few statements to get it to work without that particular database. It works all right.
See if it runs on your server, and if so, undo all my changes until it goes wrong.
What is the contents of the array returned by the database? Are there some stray quotes in?
The file name I used is build.php - should have been edit.php of course but typing was faster than thinking
PHP Code:
<? //connect to mysql //mysql_connect("localhost","user","password");
//select which database you want to edit //mysql_select_db("databasename");
//If cmd has not been initialized if(!isset($cmd)) { //display all the items //$result = mysql_query("select * from items order by type");
//run the while loop that grabs all the items scripts //while($r=mysql_fetch_array($result)) $r=2; while($r > 0) $r--; { //grab the columns from items $rbuilding=$r["building"];//take out the building $rroom=$r["room"];//take out the room $rtype=$r["type"]; $rmodel=$r["model"]; $rserial=$r["serial"]; $rspecial=$r["special"]; $rcomments=$r["comments"]; //make the title a link echo "<a href='edit.php?cmd=edit&building=$rbuilding&room=$rroom&type=$rtype&model=$rmodel&serial=$rserial&special=$rspecial&comments=$rcomments'>Edit</a>"; // echo "<br \>"; } }
jlinkels, I put your exact code into a new php file titled edit1.php and I also modified all statements involving edit.php to edit1.php. However that actually made the page look worse.
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195
Rep:
It is not worse, on the contrary it provides more information.
I created exactly the same screen output as you have by setting short_open_tag = Off in /etc/php4/apache/php.ini. It starts exactly at "0) $r--; ...." as yours does. You have to restart apache after changing.
Watch out, there might be more php.ini files around on your system.
I hope this is your problem, although I am amazed if it happens on two different systems, and you say other scripts do work. Do they use the short open tags as well, or the long <?php tag?
In PHP 2 '>' was allowed as closing tag, after that it became depreciated and unusable. I assume you don't run PHP 2, do you?
Well... That fixed the problem! I feel like an idiot right about now, but the problem is fixed. Ill bet that fixes one of my other problems with my delete php. And for the record, in Slackware the php.ini is in /etc/httpd/php.ini for anyone having the same problem I was.
No I am not using php2 I am using php-5.2.6 (current version).
And also, the pages that were in the making that I was also having problems with had <? ?>'s and were having problems. All the ones that worked were <?php 's.
Thank you for your help in solving my problem!
DragonM15
P.S. That only took 2 days of staring and pulling my hair out....
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.