-1

I'm using Range Sliders jQuery (picture), and if I'm not changing all the values every time, the form is not sending, I don't know why. If someone knows how to resolve that, that the form is sending even by modifying a single value. Thanks :))

send_settings.php

<?php
if(isset($_POST['submit_range']))
{
    $temp_min_php=$_POST['temp_min_field'];
    $temp_max_php=$_POST['temp_max_field'];
    $hum_min_php=$_POST['hum_min_field'];
    $hum_max_php=$_POST['hum_max_field'];
    $eau_min_php=$_POST['eau_min_field'];
    $eau_max_php=$_POST['eau_max_field'];
    $lum_min_php=$_POST['lum_min_field'];
    $lum_max_php=$_POST['lum_max_field'];

    $conn = mysqli_connect("localhost", "root", "toor", "db");
    $query = "UPDATE settings SET temp_min = '$temp_min_php',temp_max = '$temp_max_php',hum_min = '$hum_min_php',hum_max = '$hum_max_php',eau_min = '$eau_min_php',eau_max = '$eau_max_php',lum_min = '$lum_min_php',lum_max = '$lum_max_php'";
    $result = mysqli_query($conn, $query);
}
?>

settings.php

            <script type="text/javascript">
            $(function() {
              $( "#temp-range" ).slider({
                range: true,
                min: 0,
                max: 500,
                values: [ <?php echo $row['temp_min']; ?>, <?php echo $row['temp_max']; ?> ],
                slide: function( event, ui ) {
                  $( "#temp_amount" ).html( ui.values[ 0 ]+ " °C" + " - " + ui.values[ 1 ]+ " °C" );
              $( "#temp_min_field" ).val(ui.values[ 0 ]);
              $( "#temp_max_field" ).val(ui.values[ 1 ]);
                }
              });
              $( "#temp_amount" ).html( $( "#temp-range" ).slider( "values", 0 )+ " °C" +
               " - " + $( "#temp-range" ).slider( "values", 1 )+ " °C" );
            });
            </script>

              <div class="form-group">
                <label for="field-1" class="col-sm-3 control-label">Température (<span id="temp_amount"></span>)</label>
                <input type="hidden" id="temp_min_field" name="temp_min_field">
                <input type="hidden" id="temp_max_field" name="temp_max_field">

                <div class="col-sm-5">
                <div id="temp-range"></div>

                </div>
              </div>
Nguyễn Văn Phong
  • 13,506
  • 17
  • 39
  • 56
Komplex9
  • 31
  • 5
  • 2
    Your code is vulnerable to [**SQL injection**](https://en.wikipedia.org/wiki/SQL_injection) attacks. Instead of building queries with string concatenation, always use [**prepared statements**](https://secure.php.net/manual/en/pdo.prepare.php) with [**bound parameters**](https://secure.php.net/manual/en/pdostatement.bindparam.php). See [**this page**](https://phptherightway.com/#databases) and [**this post**](https://stackoverflow.com/questions/60174/how-can-i-prevent-sql-injection-in-php) for some good examples. – Alex Howansky Jan 16 '20 at 23:30

1 Answers1

1

The "value" attribute on your hidden inputs is only set when the slider is moved. You need to set the initial values here:

<input type="hidden" id="temp_min_field" name="temp_min_field">
<input type="hidden" id="temp_max_field" name="temp_max_field">

Like this:

<input type="hidden" id="temp_min_field" name="temp_min_field" value="<?php echo $row['temp_min']; ?>">
<input type="hidden" id="temp_max_field" name="temp_max_field" value="<?php echo $row['temp_max']; ?>">
jd182
  • 3,180
  • 6
  • 21
  • 30