Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Passing a form to PHP 1

Status
Not open for further replies.

CliveC

Programmer
Nov 21, 2001
1,222
US
Hi,
I am new to PHP and I can't seem to get this to work. Any ideas? $Name is not displaying in TEST1.PHP but everything else is.

TEST1.HTM
<html><head><title>Test 1</title></head><body>
<form method=&quot;get&quot; action=&quot;test1.php&quot;>Name:
<input type=&quot;text&quot; size=&quot;20&quot; maxlength=&quot;32&quot; name=&quot;Name&quot; />
<input type=&quot;submit&quot; value=&quot;Send&quot; />
</form></body></html>

TEST1.PHP
<html><head><title></title></head><body>
This is a test<br />
<script language=&quot;php&quot;>
Print &quot;Begin&quot;.&quot;<br>&quot;;
Print $Name.&quot;<br>&quot;;
Print &quot;End&quot;;
</script>
</body></html>
 
Have tried both post and get, neither works. With the get I see the name/value pair being passed appended to the URL but the but test1.php does not convert it to $Name.
 
Try using echo... it is much friendlier an versatile! I never did like print.
Code:
echo &quot;Begin <br>&quot;;
echo &quot;$Name <br>&quot;;
echo &quot;End&quot;;
or
Code:
echo 'Begin <br>';
echo $Name.'<br>';
echo 'End';
or
Code:
echo 'Begin <br>'.$Name.'<br>End';
or
Code:
echo &quot;Begin <br>$Name<br>End&quot;;
Any of the above should work no problem.

The form method doesn't matter.

Also, make sure your variable name ($Name) exists (the &quot;Name&quot; field of your form). $name or $NAME would each return different things.

If none of the above works, you might have some config problems? We can cross that bridge if we come to it! -gerrygerry
Go To
 
Hi gerrygerry,
I had tried that to no avail. Just to clarify I get the result:

This is a test
Begin

End

What config options might affect this?
 
TEST1.PHP
<html><head><title></title></head><body>
This is a test<br />
<script language=&quot;php&quot;>
Print &quot;Begin&quot;.&quot;<br>&quot;;
Print $Name.&quot;<br>&quot;;
Print &quot;End&quot;;
</script>
</body></html>

Try :
<?php
echo &quot;Begin <br>&quot;;
echo &quot;Name is : $name&quot;;
echo &quot;End&quot;;
?>

the <html><head><title></title></head><body>
This is a test<br />
part shouldn't b e needed but when added BEFORE the first <?php will make your page look nicer ***************************************
Party on, dudes!
[cannon]
 
Result:
This is a test
Begin
Name is :
End
 
OK .. heheehe my mistok ... Case sensitivity.
Change $name to $Name ***************************************
Party on, dudes!
[cannon]
 
I have tried all the obvious stuff and have checked for correct case of the name variable. I really think it is a config problem. I have no idea which config option might affect this behavior however.
 
I am thinking that it has to do with magic quotes. The server I am using has the following configuration.

magic_quotes_gpc off


 
Forget last msg from me. This works!

<html><head><title></title></head><body>
This is a test<br />
<script language=&quot;php&quot;>
print &quot;Begin&quot;.&quot;<br>&quot;;
print &quot;<br>&quot;;
echo($HTTP_GET_VARS['Name']);
print &quot;<br>&quot;;
print &quot;End&quot;;
</script>
</body></html>
 
Wish I knew why it worked and the standard way didn't.
 
let me just say ... VeryOdd(tm) ***************************************
Party on, dudes!
[cannon]
 
Well... um i dunno why it is doing this, but try putting this in the top of your code - it'll convert each of the $HTTP_GET_VARS[] to $var style variables:
Code:
while(list($name, $value)=$HTTP_GET_VARS) 
  ${$name} = $value;

untested, but it should work! -gerrygerry
Go To
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top