Juno Fernando Juno Fernando - 4 months ago 15
SQL Question

PHP update data from dropdown

how to update selected data from dropdown to mysql (mysql update) using php?

<form>
<select name="maintenance_mode">
<option>Maintenance On</option>
<option>Maintenance Off</option>
</select>
<button type="submit" name="update">Apply</button>
</form>


The i set column type to tinyint(1). basically just update 0 or 1.

Answer

You should use value 0/1 in select options

<?php
    if(isset($_POST['update'])){
        $connct = mysqli_connect('localhost','root','password','database');
        $value = $_POST['maintenance_mode'];
        $result = mysqli_query($connct,"UPDATE table_name SET filedname = '$value'");
    }
    ?>

<form method="post" action="">
<select name="maintenance_mode">
  <option value="1">Maintenance On</option>
  <option value="0">Maintenance Off</option>
</select>
<input type="submit" name="update" value="update">
</form>
Comments