1

I am using this url to change value of Price in my code.

http://yoursite.com/mycart.php?am=20&product=Digitizing

I want that whenever I change the value of am= in the url , the value='0' must be changed in the code dynamically according to that.

<input type='hidden' name='li_1_price' value='0' />
2
  • What does this have to do with "url-rewriting"? Commented Nov 15, 2019 at 21:23
  • So you pass the price as a query string via GET? That is not a good idea. I can just change the URL to a price I want. Use a POST request or at least check the price at the backend with your database. Commented Nov 15, 2019 at 22:02

1 Answer 1

1

You just need to intercept the value with PHP and then write the variable to the code.

<?php $amValueIs = $_GET["am"]; ?>

Then in your HTML

<input type='hidden' name='li_1_price' value='<?php echo $amValueIs; ?>' />

That's all there is to it.

EDIT as per comments: If you want to be sure that "am" has a value so you don't kick up a warning:

$amValueIs = isset($_GET["am"]) ? $_GET["am"] : "0";

Which is a shorthand for "if it's set then use it, if not give it a 0". I also added that "php" to the other open tag, just in case.

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

2 Comments

Just a few things if I may. 1) It's good to make sure that the GET array is set/not empty, same for the value in the input. 2) The <? in the value might trigger an error if they do not have short tags enabled.
Also, its good to sanitize that string, since you are effectively passing GET straight to html.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.