-1

In a PHP page, I need to open a URL when a button or link is clicked. But the URL that I open needs a variable.

Background - when the user presses the "proceed" button, a page that depends on the price will open. Different prices, different page.

I hope I'm not too obtuse, but here's a text example. I have an order confirmation page that includes the price in the URL: www.xys.com/confirm?price=100

The confirm page is where the user gets to proceed or stop. Two buttons. The price determines which page we open when the user clicks on "proceed".

So, if the price is $100, the user sees page_100.php. If the price is $200 the user sees page_200.php

The problem I am running into is that $price does not translate into a value

<?php
$price = $_GET['price'];
<input type="button" onclick="window.location.href='selector.php?$price';return false;" name="" value="Proceed">
?>

What am I missing? Thanks.

chris85
  • 23,846
  • 7
  • 34
  • 51
user3573562
  • 191
  • 11

1 Answers1

-1

Try using this

$price = 10;
echo '<input type="button" onclick="window.location.href=\'selector.php?'.$price.'\';return false;" name="" value="Proceed">';
dipesh
  • 158
  • 5
  • care to give an explanation here? – Funk Forty Niner Dec 12 '15 at 01:08
  • Thank you - I am still learning PHP and I tried everything I could, but for echo... Works exactly as desired. – user3573562 Dec 12 '15 at 03:53
  • Fred, please unmark it as a duplicate or show me where the question was already answered. – user3573562 Dec 12 '15 at 03:56
  • @user3573562 I already did, like ... over 3 hours ago http://stackoverflow.com/posts/34233603/revisions the timestamp doesn't lie. *Post Reopened by trincot, Russ, Fred -ii- php occurred 3 hours ago* prior to my comment here. – Funk Forty Niner Dec 12 '15 at 04:23
  • *"Try using this"* answers are considered as very low quality answers and does NOT explain what the problem was (and what you did to fix their code) and will not serve future visitors to the question/answer with less knowledge in order to learn. – Funk Forty Niner Dec 12 '15 at 04:26
  • Fred. The problem was, apparently, that I was using the variable inside a quoted string. Dipesh led me to the correct solution of taking the variables outside of the quotes. As a newbie to PHP I was confused because echo "this is a string with a $var in it"; does expand the variable. – user3573562 Dec 12 '15 at 22:57