0

I would like to understand why the below is not working. It is code that I have inherited and it did work on the previous webmaster's hosting.

The page has a $service variable in the URL hence the echo $_GET['service'] below in order to display the value of the variable on the page. However, we want to use that same variable value on the next page also.

At the moment I cannot use echo $_POST or I even tried echo $_GET on the next page to display this value. There must be something out of date or wrong with <input type="hidden" name="service" value="<? echo $service; ?>" />.

I tried value= echo $_GET['service']; but this did not appear to change anything,

Grateful for all help.

Thanks.

 <?php echo $_GET['service']; ?>

<form action="send-order.php" method="post">
Email<br /><input name="email" value="<?echo $email;?>" type="text" style="width: 350px;" />

<input type="hidden" name="service" value="<? echo $service; ?>" />

<input type="submit" value="Order now" /></p>
 </form>
4
  • is it still in the url on the next page? Commented Dec 15, 2011 at 22:59
  • It must be still in the url on the next page. Otherwise use SESSION. Commented Dec 15, 2011 at 23:00
  • no it disappears in the url completeyourorder.php?p=&service= Commented Dec 15, 2011 at 23:02
  • The code he has on the next page is "completeyourorder.php?p=" . $p ."&service="; Commented Dec 15, 2011 at 23:03

2 Answers 2

0

Uhm, first of all I'm seeing your form action is POST (instead of GET), so it's natural you don't appen the service input to the url...

Another thing, you're saying that the code worked previously: it might be for the use of register_globals (turned ON; in darker times that was the usual setting, now it's disabled by default) on the previous server's settings, which automatically made available to the var $service what should have been called with $_GET['service'] (or $_POST['service'], for what that matters).

I still don't understand where the "p" param comes in the URL from your comment, though. If you change the form action to action="get", you will have something like "email=something&service=somethig", but 'p' ?

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks. p is actually another variable, but for ease of posting here I only concentrated on the variable $service.
0

$service is a variable.

http://example.com?service=foo is a GET parameter.

$service is not the same as $_GET['service']

$_POST['service'] is not the same as $_GET['service']


That said, the form's method is "post". If you're posting to the same page where the form is located, then use $_POST['service'] instead. Or change the form method to "get" and use $_GET['service'].

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.