Specific cell change in Mysql

Asked

Viewed 22 times

0

Well, I am trying to change only a specific cell in Mysql using a PHP form, however, I cannot perform such action and no error is shown so I try to fix it, how can I fix the problem?

Logic

<?php

require("conecta.php");

$novoTituloDisciplina = $_POST["novo-titulo-disciplina"];
$valorDisciplina = $_POST["disciplina-a-alterar"];

$query = "update table disciplinas set 'nome_disciplina' = '{$novoTituloDisciplina}' where id = '{$valorDisciplina}'";

if(mysqli_query($conexao, $query)){
    mysqli_close();
    header("Location:../cadastra_novo.php");
}else{
    mysqli_close();
    header("Location:../index.php");
};

Form

<form action="logicas/logica-altera_disciplina.php" method="post">
    <div>
        <h3>Alterar Disciplina</h3>
    </div>
    <label>Disciplina</label>
    <select name="disciplina-a-alterar">
        <option disabled selected>-Selecione a disciplina-</option>
        <!-- Receber as opções disponíveis no banco de dados -->
        <?php
        $disciplinas = listagemDisciplinas($conexao);
        foreach ($disciplinas as $disciplina){
            ?>
            <option value="<?= $disciplina["id"] ?>"><?= $disciplina["nome_disciplina"] ?></option>
            <?php
        }
        ?>
    </select>
    <label>Novo nome</label>
    <input type="text" name="novo-titulo-disciplina">

    <button type="submit">Alterar</button>
</form>

1 answer

2


The mistake is in yours query, to perform an update does not need the word table, would look like this:

$query = "update disciplinas set 'nome_disciplina' = '{$novoTituloDisciplina}' where id = '{$valorDisciplina}'";
  • that’s what I just did here, I came to delete the question, but since you gave the correct answer, I’ll return to answer

Browser other questions tagged

You are not signed in. Login or sign up in order to post.