Ir para conteúdo
Fórum Script Brasil
  • 0

[RESOLVIDO] Erro ao Alterar (UPDATE ) da Tabela


manogaucho

Pergunta

Oi tudo bem!

Criei uma sistema para excluir ou alterar produtos de uma tabela.

o Excluir funciona.

Mas alterar não, a pagina carregar os dados, mas quando altero vai para mensagem de erro, que inserir no sistema.

or die ("Erro ao alterar Produto.");
Vamos la então.Vou colocar minhas paginas abaixo. controle.php
<?php

include ('conexao.php');



$sql = "SELECT 
            * 
        FROM 
            SS_categories
        ORDER BY 
            name";
$resultado = mysql_query($sql)
or die ("Não foi possível realizar a consulta.");

?>

<table align="center" border="2" bordercolor="#000000">

<tr>
    <th bgcolor="#FFFFCC">Nome Produto:</th>
    <th>Quantidade:</th>
    <th bgcolor="#FFFFCC">Opções</th>
</tr>

<?php


while ($linha = mysql_fetch_array($resultado, MYSQL_ASSOC))
{


    echo "<tr>";
    echo "<td>{$linha['name']}</td>";
    echo "<td>{$linha['description']}</td>";
    echo "<td><a href='alterar.php?categoryID={$linha['categoryID']}'>Alterar</a> / ";
    echo "<a href='excluir.php?categoryID={$linha['categoryID']}'>Excluir</a></td>";
    echo "</tr>";
}

echo "</table>";

?>
alterar.php
<?php

include ('conexao.php');


$sql = "SELECT 
        * 
    FROM 
        SS_categories
    WHERE 
        categoryID = ".(int)$_GET['categoryID'];
$resultado = mysql_query($sql)
or die ("Não foi possível realizar a consulta.");

$linha = mysql_fetch_array($resultado, MYSQL_ASSOC);

?>

<h1>Alterar Produto</h1>
<form action="alterar_db.php?categoryID=<?php echo $_GET['categoryID'] ?>" method="post">

    <label for="nome"></label>
    <table width="800" align="center">
      <tr>
        <td align="right" valign="top">&nbsp;</td>
        <td>&nbsp; </td>
      </tr>
      <tr>
        <td align="right" valign="top">Nome Produto: </td>
        <td><input name="name" id="name1" type="text" 
    value="<?php echo $linha['name'] ?>" />
        </td>
      </tr>
      <tr>
        <td align="right" valign="top">Quantidade:</td>
        <td><input name="description" id="description1" type="text" 
    value="<?php echo $linha['description'] ?>" />
        </td>
      </tr>
    </table>
    <input type="submit" value="Alterar" />
    

</form>
alterar_db.php
<?php

include ('conexao.php');

$sql = "UPDATE 
        SS_categories 
    SET 
        name='".mysql_real_escape_string($_POST['name'])."', 
        description='".mysql_real_escape_string($_POST['description'])."', 
    WHERE 
        categoryID = ".(int)$_GET['categoryID'];
        
$resultado = mysql_query($sql)
or die ("Erro ao alterar Produto.");

?>

<h1>Produto foi alterado com sucesso!</h1>
excluir.php
<?php

include ('conexao.php');


$sql = "DELETE FROM 
        SS_categories
    WHERE 
        categoryID = ".(int)$_GET['categoryID'];

$resultado = mysql_query($sql)
or die ("Erro ao remover notícia.");

?>

<h1>O Produto foi excluído!</h
Agora mudeio:
or die ("Erro ao alterar Produto."); 

por

or die ( mysql_error() );
erro que mostrou foi:
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 categoryID = 67' at line 6

Demais Obrigado!!!

Editado por manogaucho
Link para o comentário
Compartilhar em outros sites

2 respostass a esta questão

Posts Recomendados

  • 0

Achei o erro:

<?php

include ('conexao.php');

$sql = "UPDATE 
        SS_categories 
    SET 
        name='".mysql_real_escape_string($_POST['name'])."', 
        description='".mysql_real_escape_string($_POST['description'])."', // mudei aqui tirei a virgula
    WHERE 
        categoryID = ".(int)$_GET['categoryID'];
        
$resultado = mysql_query($sql)
or die("Erro ao alterar produto: " .mysql_error());

?>

<h1>Produto foi alterado com sucesso!</h1>
<?php
Ficou assim:
<?php

include ('conexao.php');

$sql = "UPDATE 
        SS_categories 
    SET 
        name='".mysql_real_escape_string($_POST['name'])."', 
        description='".mysql_real_escape_string($_POST['description'])."' //ficou assim
    WHERE 
        categoryID = ".(int)$_GET['categoryID'];
        
$resultado = mysql_query($sql)
or die("Erro ao alterar produto: " .mysql_error());

?>

<h1>Produto foi alterado com sucesso!</h1>
<?php

Agradeço desde já aajuda de todos!!!

tópico encerrado!!!

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      651,9k
×
×
  • Criar Novo...