Jump to content

Apache won't parse PHP files


fert

Recommended Posts

I have a PHP file that contains code like this:
[code]
echo "<form method=\"post\" action=\"index.php\" name=\"post\">";
echo "<textarea rows=\"5\" cols=\"30\" name=\"text\"></textarea>";
echo "<p><input type=\"submit\" value=\"Save\"></p></form>";
[/code]
But when i try to run it i get a blank page and it's not because the code has errors it. How can i fix this?
Link to comment
https://forums.phpfreaks.com/topic/29264-apache-wont-parse-php-files/
Share on other sites

Try this on its own:

[code]<?php
echo "<form method='post' action='index.php' name='post'>";
echo "<textarea rows='5' cols='30' name='text'></textarea>";
echo "<p><input type='submit' value='Save'></p></form>";
?>[/code]

I hope you are putting the <?php and ?> tags? Also you need to check your apache logs for errors etc.
Also - try viewing the webpage with a different browser.
-steve
[code]
<?php
echo "<form method='post' action='index.php' name='post'>";
echo "<textarea rows='5' cols='30' name='text'></textarea>";
echo "<p><input type='submit' value='Save'></p></form>";
?>[/code]
that works

[code]
<?php
$var=1;

if($var==1)
{
echo "<form method='post' action='index.php' name='post'>";
echo "<textarea rows='5' cols='30' name='text'></textarea>";
echo "<p><input type='submit' value='Save'></p></form>";
}
else
if($var==2)
{
echo $var;
}
else
{
die("Error");
}
[/code]
that works

[code]
<?php
$var=$_GET[var];

if($var==1)
{
echo "<form method='post' action='index.php' name='post'>";
echo "<textarea rows='5' cols='30' name='text'></textarea>";
echo "<p><input type='submit' value='Save'></p></form>";
}
else
if($var==2)
{
echo $var;
}
else
{
die("Error");
}
?>
[/code]
that doesn't work and there are no errors in the log.
Try this and see what it echos out:
[code]<?php
$var=$_GET[var];
echo $var;

if($var==1)
{
echo "<form method='post' action='index.php' name='post'>";
echo "<textarea rows='5' cols='30' name='text'></textarea>";
echo "<p><input type='submit' value='Save'></p></form>";
}
else
if($var==2)
{
echo $var;
}
else
{
die("Error");
}
?>[/code]

Debuuuuug it.

-steve
There is an error and its to do with line2:
$var=$_GET[var];

You should put the key in quotes if its a string. Otherwise PHP will think you're using a constant. Also if you key is also a reserved keyword and you're not putting it in quotes then you'll get an error/blank page! In your code [b]var[/b] is a reserved keyword and PHP is getting confused.

So line 2 should be like this:
[code=php:0]$var=$_GET['var'];[/code]
try this (revised code by wildeen  ;) )
[code]<?php
$test1=$_GET['var'];
echo " Variable should be here: $test1";

if($var==1)
{
echo "<form method='post' action='index.php' name='post'>";
echo "<textarea rows='5' cols='30' name='text'></textarea>";
echo "<p><input type='submit' value='Save'></p></form>";
}
else
if($var==2)
{
echo $var;
}
else
{
die("Error");
}
?>[/code]

Also - what version of php do you have running? Do you have PHP globals switched on?

-steve
Wouldn't you want to change all $var's to $test1 in your example code?

I have added test code for you to try out

[code]
<html>

<body>

<a href="document.php?test=10">Click Link</a><br><br>

<?php

$sSelf = $_SERVER['PHP_SELF'];

echo $sSelf . "<br>\n";

$sTest = $_GET['test'];

echo $sTest . "\n";

?>

</body>

</html>
[/code]


Run the test code above, change document.php to whatever the document name is (so you can click the link to set test to equal 10).

Should output this (when viewing source) when test = nothing:

[code]
<html>

<body>

<a href="document.php?test=10">Click Link</a><br><br>

document.php<br>


</body>

</html>
[/code]


Should look like this (when you view source) when you click the link:

[code]
<html>

<body>

<a href="document.php?test=10">Click Link</a><br><br>

document.php<br>
10

</body>

</html>
[/code]


Give the source and content of the page when you load it, then when you click the link.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.