-4

I'll try to explain myself good as i can, I have this "value"

Picture here

And i want to do something that, when I enter to this link for example: http://example.com/index.php?value=50 It will insert the number 50 into the value..

<input type="number" name="amount" min="1" max="5000" value=""  />

Someone can help me please?

Thanks everyone the problem solved

Ben
  • 1
  • 2

3 Answers3

0
<input type="number" name="amount" min="1" max="5000" value="<?php echo (isset($_GET['value']) ? $_GET['value'] : '') ?>"  />

isset() is in place just in case the 'value' parameter has not been passed via the url

Zentag
  • 701
  • 1
  • 5
  • 2
0

URLs usually come in this format (see query strings on Wikipedia):

protocol://baseurl/path?queryparam1=value1&queryparam2=value2&queryparam3=value3...

In your URL, value is a GET query parameter and 50 is its value.

Access the query parameters with the PHP $_GET global array. Its keys are set to the values of the query parameters.

For example, the value "50" will be stored in $_GET['value']. You can store this in the value of your input element like so:

<input type="number" name="amount" min="1" max="5000" value="<?= $_GET['value'] ?>" />

(<?= $value ?> is the shortcut for <?php echo $value ?>, and can be used in PHP5.4+)

Jonathan Lam
  • 16,831
  • 17
  • 68
  • 94
0

First, you have to retrieve the value from the URL (don't forget to sanitize the user input): <?php $value = htmlspecialchars($_GET['value']); ?>

Then, when you want to insert the value in your html, you just use <?php echo $value; ?>

For instance <input type="number" name="amount" min="1" max="5000" value="<?php echo $value; ?>" />

Faibbus
  • 1,115
  • 10
  • 18