Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Pessoal me da uma força ai, fiz um banco de dados, Editavel, quando tenho a linha abaixo está assim:
**$query = mysqli_query($link,"update contato set nome='$nome', telefone='$telefone', where id='$id';");**
Não consigo alterar os dados pois aparece essa mensagem de erro abaixo:
**Erro: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where id='$id'' at line 1**
Quando APAGO o **where id='$id' ** Eu consigo alterar, porem todos os Dados do banco alteram também, como se um alterasse todos.
vou postar o código inteiro:
<?php
$id = filter_input(INPUT_GET, "id");
$nome = filter_input(INPUT_GET, "nome");
$telefone = filter_input(INPUT_GET, "telefone");
$link = mysqli_connect("localhost", "root", "", "agenda_telefonica");
if($link){
$query = mysqli_query($link,"update contato set nome='$nome', telefone='$telefone', where id='$id';");
if ($query) {
header("Location: index.php");
}else{
die("Erro: ". mysqli_error($link));
}
}else{
die("Erro: ". mysqli_error($link));
}>
13 horas atrás, Matheus Tavares disse:
O problema está na virgula entre o último campo e o where. Você precisa removê-la.
AQUI
UPDATE xxx = 'yyy', foo = 'bar', WHERE id = 5
Eu tentei corrigir mais não deu certo, continua aparecendo essa mensagem...
***Erro: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where id=' at line 1***
se alguém puder reescrever esse código pra mim me ajudaria muito.
O problema está na virgula entre o último campo e o where. Você precisa removê-la.
AQUI
UPDATE xxx = 'yyy', foo = 'bar', WHERE id = 5