Pergunta

So, when I have a select form like this:

<form method="post" action="" name="change_slider">
      <label class="control-label"><?php echo $LANG['admin']['global']['Slider']; ?></label>
      <div class="controls">
      <select name="slider">
        <option name="sex" value="false">none</option>
        <option name="sex" value="poepCru3er">Cru3er</option>
      </select>
      </div>

      <div class="form-actions">
        <button type="submit" name="slideredit" class="btn btn-primary"><?php echo $LANG['admin']['global']['submit']; ?></button> 
      </div>          
    </form>

And I want the selected value in my database should I be doing this:

if(isset($_POST['change_slider'])) {
  $name = $_POST['slider'];
  $errorsslide = $users->changeSlider($name);
}

Because it doesn't work. By the way, this is the changeSlider function, in case it's necessary

public function changeSlider($name) {
$errorsslide = array();
$stmt = $this->mysqli->prepare("UPDATE cms_funtions SET value=? WHERE title='Slider'");
$stmt->bind_param('s', $name);
$stmt->execute();
$stmt->close();
$errorsslide[] = "<div class='alert alert-success'><button type='button' class='close' data-dismiss='alert'>x</button><strong>Success!</strong> Slider Changed successfully!</div>";
return $errorsslide;
}

So, long story short, I want the selected value of the form to go into my DB.

Does anyone see my mistake?

Foi útil?

Solução

There is no form field named change_slider so the code after this will never run as the condition is always false:

if(isset($_POST['change_slider'])) {

You should change it to something like:

if($_SERVER['REQUEST_METHOD'] === 'POST') {
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top