0
I am getting the data from a POST and trying to update a mysql table, but UPDATE does not work at all.
If I use as described below, just replace the values with empty.
<?php
require('../configs/conect_apostas.php');
$id=$_SESSION['id'];
$selectOption = $_POST['selectOption'];
$dadosAlterar = $_POST['dadosAlterar'];
$sql2 = "UPDATE dados SET alunos = '$dadosAlterar' WHERE 1";
if ($mysqli->query($sql2) === TRUE) {
echo "Sucesso!";
}
?>
If I give a echo $dadosAlterar
get the value correctly.
If I use the code below, UPDATE is performed successfully.
<?php
require('../configs/conect_apostas.php');
$id=$_SESSION['id'];
$selectOption = $_POST['selectOption'];
$dadosAlterar = "Mateus";
$sql2 = "UPDATE dados SET alunos = '$dadosAlterar' WHERE 1";
if ($mysqli->query($sql2) === TRUE) {
echo "Sucesso!";
}
?>
If I perform an INSERT works correctly with the POST, but I need to perform an UPDATE.
Can you post the error generated in the update? ?
– Felipe Fernandes
Felipe, no error, just replace with empty. The success query, replacing what you have with empty. And yes, I’ve tried running the query directly and it works.
– Mateus Antunes
INSERT INTO data (students) values ('$dadsAlter') ON DUPLICATE KEY UPDATE students = '$dadsAlter' tries using this method as it facilitates checking whether you are inserting a new record or changing an existing one
– Felipe Fernandes
You have already printed
$sql2
before running to see what is being mounted?– bfavaretto
bfavaretto, I just printed it out, and by amazing it looks like the variable $dadsAltering is correct. echo of $sql2 -> UPDATE data SET students = 'Matthew' WHERE 1 Receiving data correctly from POST.
– Mateus Antunes
Felipe Fernandes, tried with the ON DUPLICATE KEY UPDATE, but still is replacing with empty.
– Mateus Antunes