Jump to content

Recommended Posts

I have a form set up like this:

 

<form action="?action=update" method="post">
<input type="text" name="way" />
<input type="text" name="zip" />
<input type="submit" />
</form>

 

When I submit the form it just take you back to the original page (which is intended) but without ?action=update.

 

None of the post vars show up in PHP.

 

Even when i use get, it takes me to ?way=abc&zip=xyz.

 

I don't get it!

Link to comment
https://forums.phpfreaks.com/topic/141362-using-post-and-get-vars-together/
Share on other sites

Do something like this at the start of your script:

<?php
$action = ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['action']))?$_GET['action']:'';
$action = ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action']))?$_POST['action']:'';
?>

Ken

 

 

<?php
$action = ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['action']))?$_GET['action']:'';
$action = ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action']))?$_POST['action']:'';
?>

Wouldn't that overwrite itself? If you had a GET var, but not a POST, action would be set to ""

 

@ OP, I go to http://www.fhsgsa.org/dw2/cart.php?action=update

 

However get the errors:

Notice: Undefined variable: shipzip in /home/content/f/h/s/fhsgsa/html/dw2/cart.php on line 8

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/h/s/fhsgsa/html/dw2/cart.php:8) in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 219

yeah, i have this right up at the top.

 

$action = (isset($_GET['action']) && $_GET['action'] != '') ? $_GET['action'] : 'view';

$shipway = (isset($_POST['shipway']) && $_POST['shipway'] != '' && $_POST['shipway'] != NULL) ? $_POST['shipway'] : '03';

$shipzip = (isset($_POST['shipzip']) && $_POST['shipzip'] != '') ? $_POST['shipzip'] : NULL;

 

but even if i echo $_GET['action'] or $_POST['shipzip'], its undefined.

@KPhilip i fixed that. you caught me in the middle of a quick update. now at the top i have

 

$action = (isset($_GET['action']) && $_GET['action'] != '') ? $_GET['action'] : 'view';

$shipway = (isset($_POST['shipway']) && $_POST['shipway'] != '' && $_POST['shipway'] != NULL) ? $_POST['shipway'] : '03';

$shipzip = (isset($_POST['shipzip']) && $_POST['shipzip'] != '') ? $_POST['shipzip'] : NULL;

echo $_POST['shipzip'];

 

<?php
$action = ($_SERVER['REQUEST_METHOD'] == 'GET' && isset($_GET['action']))?$_GET['action']:'';
$action = ($_SERVER['REQUEST_METHOD'] == 'POST' && isset($_POST['action']))?$_POST['action']:'';
?>

Wouldn't that overwrite itself? If you had a GET var, but not a POST, action would be set to ""

 

@ OP, I go to http://www.fhsgsa.org/dw2/cart.php?action=update

 

However get the errors:

Notice: Undefined variable: shipzip in /home/content/f/h/s/fhsgsa/html/dw2/cart.php on line 8

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/h/s/fhsgsa/html/dw2/cart.php:8) in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 219

Hopefully you're still fixing it,

Notice: Undefined index: shipzip in /home/content/f/h/s/fhsgsa/html/dw2/cart.php on line 9

 

Notice: Undefined index: hidCartId in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 164

 

Notice: Undefined index: hidProductId in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 165

 

Notice: Undefined index: txtQty in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 166

 

Notice: Undefined index: shipzip in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 167

 

Notice: Undefined index: shipway in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 168

 

Notice: Undefined variable: returnUrl in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 217

 

Notice: Undefined index: shop_return_url in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 217

 

Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/h/s/fhsgsa/html/dw2/cart.php:9) in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 217

Okay - after putting another item in my cart (apparently it emptied itself)

Zip Code

Warning: Cannot modify header information - headers already sent by (output started at /home/content/f/h/s/fhsgsa/html/dw2/cart.php:9) in /home/content/f/h/s/fhsgsa/html/dw2/library/cart-functions.php on line 219

and:

Notice: Undefined index: shipzip in /home/content/f/h/s/fhsgsa/html/dw2/cart.php on line 9

 

I'm pretty sure the action=?GETVARS is browser dependent - some will run it, others wont (can anybody confirm this?)

Ok, so if I don't do the echo on line 9 of cart.php, I think that should fix things. Which I have done.

 

So what I should probably do is:

 

<form action="cart.php" method="post">

<input type="hidden" name="action" value="update" />

 

and...

 

if(isset($_GET['action']) && $_GET['action'] != '') {$action = $_GET['action'];}

elseif(isset($_POST['action']) && $_POST['action'] != '') {$action = $_POST['action'];}

else{$action = 'view';}

<?php
if(isset($_GET['action']) && $_GET['action'] != '') {$action = $_GET['action'];}
elseif(isset($_POST['action']) && $_POST['action'] != '') {$action = $_POST['action'];}
else{$action = 'view';}
?>

 

Yeah, that's what I would do - of course don't forget to filter it (possibly use an array/switch to check to see if the action is acceptable)

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.