Page 1 of 2

Apache not interpreting in some circumstances

Posted: Tue Apr 19, 2011 8:50 am
by Simbachips
The problem is that the post and get functions do not work,

Code: Select all

<html>
<body>
<form action="Welcome.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
.

The output I get with the above code is something like: Hello ! and you are ! ... notice the problem. Even if I throw a print statement where the $_POST statement would be still the same outcome.

Also I got this slightly more complicated code that I am trying to get working and I believe that it is not working because of the post\get prob. Below is a simple example I pulled from another website as an example of the more complicated code I was talking about. The prototype.js is in the same dir and so is test.php

Code: Select all

<html> 
	<title>php-learn-it.com - php ajax form submit</title> 
	<head>		
		<script type="text/javascript" src="prototype.js"></script> 
		<script> 
 
			function sendRequest() {
				new Ajax.Request("test.php", 
					{ 
					method: 'post', 
					postBody: 'name='+ $F('name'),
					onComplete: showResponse 
					});
				}
 
			function showResponse(req){
				$('show').innerHTML= req.responseText;
			}
		</script> 
	</head> 
 
	<body> 
		<form id="test" onsubmit="return false;"> 
			Name: <input type="text" name="name" id="name" > 
			<input type="submit" value="submit" onClick="sendRequest()"> 
		</form> 
		
		<div id="show"></div> 
		<br/><br/> 
	</body> 
</html> 
test.php
<?php

if($_POST["name"] == "")
	echo "name is empty";
else
	echo "you typed ".$_POST["name"];
?>
There is no errors with the above code, when I click submit nothing happens. I put the above code there in hope that someone would agree with me about the strangeness. Hopefully I have been clear and thanks to anyone who replies.

Re: Apache not interpreting in some circumstances

Posted: Tue Apr 19, 2011 10:22 am
by fugix
can i see your welcome.php code please

Re: Apache not interpreting in some circumstances

Posted: Tue Apr 19, 2011 10:25 am
by incubi
You're right this looks okay.

Code: Select all

<?php
?>
<html>
<body>
<form action="link.php" method="post">
Name: <input type="text" name="fname" />
Age: <input type="text" name="age" />
<input type="submit" />
</form>
</body>
</html>
<?php

print $_POST["fname"];
?>

What happens when you use GET? It could be a register_globals issue too.

Lee

Re: Apache not interpreting in some circumstances

Posted: Tue Apr 19, 2011 6:25 pm
by Simbachips
incubi wrote: What happens when you use GET? It could be a register_globals issue too.
Lee
Hey lee thanks for the reply, when I use the GET statement the values do get passed in the URL but same problem as before. What did you mean by register_global problem?
fugix wrote:can i see your welcome.php code please

Code: Select all

<html>
<body>

Welcome <?php $_REQUEST["fname"]; ?>!<br />
You are <?php $_REQUEST["age"]; ?> years old.

</body>
</html>
I have also tried $_POST same problem.

Thanks

Re: Apache not interpreting in some circumstances

Posted: Tue Apr 19, 2011 7:20 pm
by incubi
Hi,

You can try changing the register_globals setting in the php.ini BUT, just for testing do not leave it on, see link.
http://wiki.geeklog.net/index.php/Regis ... 24_REQUEST
I'm not sure it will matter but in your case toggle it and test.

Some things to try:
Try setting the var manually to see if it prints?

Code: Select all

$mytest = "Lee";
Welcome <?php $mytest; ?>!<br />
Its silly but this will tell you for sure its in the POST var.

Also, I've seen a lot of issues out here that are the result of bad script flow. For example one issue where he couldn't understand why he got two entries in the DB. It was because the insert would run once when he loaded the script and again when he hit the submit button. But I digress, point is be sure your script is designed right use functions and if isset so you code runs when you want it to.

Re: Apache not interpreting in some circumstances

Posted: Tue Apr 19, 2011 8:17 pm
by fugix
I would set an if isset $_POST condition to see if it is set at all. Do you get any errors when trying to store these vars?

Re: Apache not interpreting in some circumstances

Posted: Tue Apr 19, 2011 9:48 pm
by Simbachips
I went off and tried and retried every suggestion nothing worked, below is the code I wrote to test so that everyone is happy I did it right. I should add that only the html was visible none of the error checking statements were and that the below was all tested with register_global = on.

Code: Select all

<html>
<body>
Welcome 
<?php 
$mytest = "Lee"
print"$mytest"; ?>!<br />
</body>
</html>
then...
<html>
<body>
Is it working: <?php if (isset($_POST["submit"];)) {
	$name=$_POST['fname'];
    print"HI $name";
}else { echo"There is nothing set in here.";
	}?><br />
</body>
</html>
then...
Is it working: <?php if (isset($_POST["fname"];)) {
    echo "This var is set so I will print.";
}else { echo"There is nothing set in here.";
	}?><br />
	
<?php if (isset($_REQUEST["age"];)) {
    echo "This var is set so I will print.";
}else { echo"There is nothing set in here.";
	}?>
fugix wrote:Do you get any errors when trying to store these vars?
No I do not.

Ok so the problem now is clearly that the code within the php file is not being interpreted when the file is being invoked by the action command. Kinda what I suspected, now I know the apache server is working as I can call a php file to be rendered in the browser by using the localhost/blah/blah.php. If I am saying things that don't make sense please correct me.

Re: Apache not interpreting in some circumstances

Posted: Tue Apr 19, 2011 10:49 pm
by fugix
I think it's because in your welcome.php you aren't echoing the post values...

Re: Apache not interpreting in some circumstances

Posted: Tue Apr 19, 2011 11:02 pm
by Simbachips
fugix wrote:I think it's because in your welcome.php you aren't echoing the post values...
This is likely not true, however I humour...

Code: Select all

<html>
<body>
Welcome <?php 
echo $_POST[fname]; ?> years old.
</body>
</html>

OR

<html>
<body>
Welcome <?php 
echo "$_POST[fname]"; ?> years old.
</body>
</html>
I still think it has something to do with when I use the action command to invoke other pages the problem arises... remember if a go localhost/do/do.php all my php scripts works even Welcome.php

And thanks to all that have replied so far, much appreciated.

Re: Apache not interpreting in some circumstances

Posted: Wed Apr 20, 2011 9:54 am
by fugix
The only other thing that I can think of is to make your action pages direct paths instead of relative. Like http://localhost/example/welcome.php

Re: Apache not interpreting in some circumstances

Posted: Wed Apr 20, 2011 1:34 pm
by incubi
I'm not sure what this is but both POST vars are missing quotes. :)
<html>
<body>
Welcome <?php
echo $_POST[fname]; ?> years old.
</body>
</html>

OR

<html>
<body>
Welcome <?php
echo "$_POST[fname]"; ?> years old.
</body>
In any case please try this in your form. Of course remove the other form tag first.

Code: Select all

print '<FORM  NAME="form1"  ACTION="'.$_SERVER['PHP_SELF'].'" METHOD="POST">';
it will rule out the action call issue.

Thanks

Lee

Re: Apache not interpreting in some circumstances

Posted: Wed Apr 20, 2011 3:39 pm
by strafingmoose
As a side note, get Firebug for Firefox if you are going to do AJAX stuff.

This way, in the console, you can see the content of your request and see the results of it.

Re: Apache not interpreting in some circumstances

Posted: Wed Apr 20, 2011 3:41 pm
by incubi
Agreed, it works great!!! :)


Lee

Re: Apache not interpreting in some circumstances

Posted: Wed Apr 20, 2011 5:10 pm
by McInfo
Simbachips, when you navigate to a PHP file in your browser, can you see the PHP code when you view the page's HTML source? Have you ever successfully run a PHP script on your Apache server? Can you find the string "php" anywhere in your httpd.conf file or other *.conf file?

Re: Apache not interpreting in some circumstances

Posted: Wed Apr 20, 2011 7:55 pm
by Simbachips
McInfo wrote:Can you find the string "php" anywhere in your httpd.conf file or other *.conf file?
I am pretty sure that the php module is installed onto the apache server, would I be able to successfully use localhost/goo/gah.php if I did not?

I searched httpd.conf for php and below are the three values it returned.

<IfModule dir_module>
DirectoryIndex index.php index.pl index.cgi index.asp index.shtml index.html index.htm \
default.php default.pl default.cgi default.asp default.shtml default.html default.htm \
home.php home.pl home.cgi home.asp home.shtml home.html home.htm
</IfModule>
incubi wrote:I'm not sure what this is but both POST vars are missing quotes.
I thought at least one of the ways I did it was correct... You are right I am missing the quotes.
incubi wrote:In any case please try this in your form. Of course remove the other form tag first.

Code: Select all

print '<FORM  NAME="form1"  ACTION="'.$_SERVER['PHP_SELF'].'" METHOD="POST">';
I tried this:

Code: Select all

<html>
<body>
<?php
if(isset($_POST['submit']))
{
    $name = $_POST['name'];
    echo "User Has submitted the form and entered this name : <b> $name </b>";
    echo "<br>I can use the following form again to enter a new name?";
}
?>
<form name="form1" action=" '.$_SERVER['PHP_SELF'].' " method="POST">
Name: <input type="text" name="name" />
<input type="submit"/>
</form>
</body>
</html>
The error I get after I click submit is: First in the URL I get localhost/Code2/'.$_SERVER['PHP_SELF'].'

on the page its self:

Object not found!

The requested URL was not found on this server. The link on the referring page seems to be wrong or outdated. Please inform the author of that page about the error.

If you think this is a server error, please contact the webmaster.

Error 404

localhost
21.04.2011 12:58:41
Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1