[Resolvido] Erro ao Alterar (UPDATE ) da Tabela
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"> </td>
<td> </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
Demais Obrigado!!!
Discussão (4)
Carregando comentários...