Page 1 of 1

$_POST only works from html to php but not php to php.

Posted: Sun Mar 02, 2008 7:51 pm
by ashebrian
~pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


When i use the following code in my [color=#FF0000]voucher.html[/color] the [color=#FF0000]$_POST[/color] works when its sent to [color=#FF0000]voucherProcess.php[/color]. But the in voucherProcess.php as the [color=#FF0000]quantity[/color] value selected will not bring u to the correct page. It brings u to the default one.

[color=#FF0000]voucher.html[/color]

Code: Select all

 
<form name='availablevouchers' action='voucherProcess.php' method='post'>
<input name="vouchertype" type="hidden" value="You Choose The Amount" />
<select name='price' id='price'>
<option value='Price'>Choose Amount</option>
<option value='50'>50 EURO</option>
<option value='100'>100 EURO</option>
<option value='150'>150 EURO</option>
<option value='200'>200 EURO</option>
<option value='250'>250 EURO</option>
<option value='300'>300 EURO</option>
<option value='350'>350 EURO</option>
<option value='400'>400 EURO</option>
<option value='450'>450 EURO</option>
<option value='500'>500 EURO</option>
</select>
 
<select name='quantity' id='quantity'>
<option value='0'>None</option>
<option value='1'>1</option>
<option value='2'>2</option>
<option value='3'>3</option>
<option value='4'>4</option>
<option value='5'>5</option>
</select>
voucherProcess.php

Code: Select all

<?php
 // alway filter inputs for security, now this must be an integer
 $quantity = intval($_POST['quantity']);
 // now check if it is in the range
 if (($quantity >= 1) && ($quantity <= 6))
 {
    header('Location: voucherLoaded' . $quantity . '.php');
 } else {
    echo header('Location: error.php');
}
?>
However, as i tried to change the html file to a php file the quantity vaule brought me to the correct page. BUT the $_POST did not work.

Changes made in the new php file voucher.php:

Code: Select all

<form name='availablevouchers' action='voucherProcess.php' method='post'>
<input name="vouchertype" type="hidden" id="vouchertype" value="You Choose The Amount" />
****ADDED****
<input type="hidden" name="price" id="price" value="<?php echo intval($_POST['price']); ?>"/>
<input type="hidden" name="quantity" id="quantity" value="<?php echo intval($_POST['quantity']); ?>"/>
<input type="hidden" name="deliverymethod" id="deliverymethod" value="<?php echo intval($_POST['deliverymethod']); ?>"/>
Am stuck on this......any hints?


~pickle | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Re: $_POST only works from html to php but not php to php.

Posted: Sun Mar 02, 2008 7:54 pm
by Christopher
You might need the full URL in the redirect:

Code: Select all

header('Location: http://www.mysite.com/voucherLoaded' . $quantity . '.php');

Re: $_POST only works from html to php but not php to php.

Posted: Sun Mar 02, 2008 8:54 pm
by Sekka
Why are you using $_POST in voucher.php? Does another form submit to this page and it's action is voucher.php?

$_POST contains information from the previous page's form if it's method is set to 'post'. Once the action page has finished executing (a redirect classes as a finish of execution), the $_POST is cleared and will no longer exist.

Any of that help? :(

Re: $_POST only works from html to php but not php to php.

Posted: Mon Mar 03, 2008 6:49 am
by ashebrian
I see... so if a forms info is not posted to voucher.php then there's no need for $_post. I got rid of it. But once i go to the next page the correct page comes up BUT the results for the of the previous form is 0 for all my $_POST. Why is this?

Re: $_POST only works from html to php but not php to php.

Posted: Mon Mar 03, 2008 7:19 am
by thomas777neo
On the voucherProcess.php, type the following:

Code: Select all

<?php
var_dump($_POST);
?>
Then copy the output on this forum so that we can see what is going on. Also send the version of PHP that you are using. You might be using an older version that does not use $_POST but the older command.

Re: $_POST only works from html to php but not php to php.

Posted: Mon Mar 03, 2008 7:40 am
by ashebrian
Output:

Code: Select all

Voucher:    0
Total Amount:   € 0
How Many?   0
Voucher Delivery:   0
 
i'm using:
php 5.2.5
Still having same prob.

Re: $_POST only works from html to php but not php to php.

Posted: Mon Mar 03, 2008 8:17 pm
by ashebrian
Actually.....the above output was on my localhost but online the output error is:
array(4) { ["vouchertype"]=> string(21) "You Choose The Amount" ["quantity"]=> string(1) "1" ["price"]=> string(3) "200" ["deliverymethod"]=> string(16) "offline_customer" }
Warning: Cannot modify header information - headers already sent by (output started at C:\Inetpub\vhosts\voucherProcess.php:2) in C:\Inetpub\vhosts\voucherProcess.php on line 8
Do you understand this?

Re: $_POST only works from html to php but not php to php.

Posted: Sat Mar 08, 2008 8:14 pm
by ashebrian
does anyone know where this error comes from? or how to solve it?

Re: $_POST only works from html to php but not php to php.

Posted: Sun Mar 09, 2008 10:35 am
by markusn00b
it should be

Code: Select all

 
header("Location: ... ");
// not!
echo header("Location: ... ");
 

Re: $_POST only works from html to php but not php to php.

Posted: Sun Mar 09, 2008 4:32 pm
by ashebrian
cheers, i changed that but it didnt change the error msg. if i change my form action to one of the pages i wanted loaded (like voucherLoaded1.php) and NOT voucherProcess.php then the $_POST works without a bother. BUT i want to be moved to a page after an option was selected in the first page. My only option is to do what i'm doing at the moment but can't sort this error. I Believe that maybe $_POST will not work once i use voucherProcess.php, and prob will never work. Any way around this?

Re: $_POST only works from html to php but not php to php.

Posted: Sun Mar 09, 2008 8:32 pm
by ashebrian
cheers, i solved my prob now. i used a javascript instead of voucherProcess.php. It does the job.

Re: $_POST only works from html to php but not php to php.

Posted: Mon Mar 10, 2008 7:50 am
by kryles
until users disable JavaScript.

Re: $_POST only works from html to php but not php to php.

Posted: Mon Mar 10, 2008 6:07 pm
by ashebrian
yeah.....everybody knows that. To be honest i wanted to fix the PHP script coz of that but PHP didn't work and i didn't seem to find a way around it. If you know otherwise. Please post it here.

Cheers