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
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
Link to comment
Share on other sites

[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.
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.