Page 1 of 1

Post and Get are not working, please help

Posted: Sat Jul 03, 2010 3:06 am
by shinyjoy
Hi
I have set up php mysql and apache server by installing XAMPP on my pc which is windows xp sp2. And trying to get the following code run but i am not getting the variables through the post or get why, please help me.
Thanks in advance.

my code:
<body>
<H2>Search Results</H2>
<BR>
<FORM ACTION="result.php" METHOD="POST">
Enter name, or part of the name, of the shops you wanted:
<BR>
<INPUT NAME = "name" TYPE = TEXT>
<BR>
<INPUT TYPE= SUBMIT VALUE="Search">
</FORM>
</body>

php page code: result.php
<?
echo $_POST['name'];
?>

I tried every thing like $_REQUEST['name'] and http_Post_var
but nothing is working when i click on a submit, it displaying a blank page why? where is the problem;

Re: Post and Get are not working, please help

Posted: Sat Jul 03, 2010 3:56 am
by requinix
The page isn't blank - it just looks that way to you.

Code: Select all

<?php
echo $_POST['name'];
?>

Re: Post and Get are not working, please help

Posted: Sat Jul 03, 2010 5:21 am
by shinyjoy
actually it's not passing any variable

even if wrote code like this, i couldn't get any thing. see below..

Code: Select all

<?php
$var = $_POST['name'];
echo $var;
?>  

Re: Post and Get are not working, please help

Posted: Mon Jul 05, 2010 1:51 pm
by rolanddev

Code: Select all

<body>
<H2>Search Results</H2>
<BR>
<FORM ACTION=<?php echo $_SERVER[PHP_SELF]; ?> METHOD="POST">
Enter name, or part of the name, of the shops you wanted:
<BR>
<INPUT NAME = "name" TYPE = TEXT>
<BR>
<INPUT TYPE= SUBMIT VALUE="Search">
</FORM>
</body>

<?php
echo $_POST["name"];
?>
Use this code, I corrected it!

Re: Post and Get are not working, please help

Posted: Mon Jul 05, 2010 3:03 pm
by internet-solution
shinyjoy wrote:actually it's not passing any variable

even if wrote code like this, i couldn't get any thing. see below..

Code: Select all

<?php
$var = $_POST['name'];
echo $var;
?>  

Try dumping the $_POST array, and see its content

Code: Select all

echo "<pre>";
print_r($_POST);
echo "</pre>";

Other option is to set form method to get and see what is passed in the result.php's url.
---------------
rolanddev wrote:

Code: Select all

<body>
<H2>Search Results</H2>
<BR>
<FORM ACTION=<?php echo $_SERVER[PHP_SELF]; ?> METHOD="POST">

Use this code, I corrected it!
You don't need ACTION=<?php echo $_SERVER[PHP_SELF]; ?> part. if action parameter is ommitted, the form is posted to the file containing the form (i.e. $_SERVER[PHP_SELF]).