Eu consegui fazer +/- o que eu queria, mas está dando um erro que eu não estou conseguindo resolver, será que poderiam dar um HELP! ? Eu criei um banco de dados e + 3 arquivos: add_not.php - Faz a conexão com o Banco de dados e executa os comandos de inc(incluir), alt(alterar) e exc(excluir); en_not.php - Formulario para Incluir e Editar noticias; lista.php - Exibe todas as noticias do banco de dados, e contém os links para Inclusão, edição e exclusão. add_not.php: <?php
//Conexão com Banco de Dados
$conn = mysql_connect('localhost', 'root', '');
$db = mysql_select_db("sis_noticia");
//Verificação do tipo de ação passada por POST
$acao = empty($_POST[acao]) ? $_GET[acao] : $_POST[acao];
//Inclusão da Noticia
if($acao == 'inc') (
$i_noticia = "INSERT INTO noticia (titulo, chamada, texto) VALUES
('$_POST[titulo]','$_POST[chamada]','$_POST[texto]')";
mysql_query($i_noticia) or die (mysql_error());
) else (
if ($acao == 'alt') (
$u_noticia = "UPADTE noticia
SET titulo = '($_POST[titulo])',
chamada = '($_POST[chamada])',
texto = '($_POST[texto]);
WHERE id = '($_POST[id])'";
mysql_query($u_noticia);
) else (
$d_noticia = "DELETE FROM noticia
WHERE id = '($_GET[id])'";
mysql_query($d_noticia) or die (mysql_error());
)
)
header('Location:lista.php');
?>
Lista.php
<?php
$conn = mysql_connect('localhost','root','');
$db = mysql_select_db('sis_noticia');
$s_noticia = "SELECT *
FROM noticia
ORDER BY id DESC
LIMIT 0,30";
$t_noticia = mysql_query($s_noticia) or die(mysql_error());
?>
<h1>Lista de Noticias Cadastradas</h1>
<table width="600" border="1">
<tr>
<td>Noticias</td>
<td>Alterar</td>
<td>Excluir</td>
</tr>
<?php while($noticia = mysql_fetch_array($t_noticia)) ( ?>
<tr>
<td><? echo $noticia[titulo]; ?></td>
<td><a href="en_not?acao=alt&id==<? echo $noticia[id]; ?>">Alterar</a></td>
<td><a href="add_not?acao=exc&id==<? echo $noticia[id]; ?>">Excluir</a></td>
</tr>
<?php ) ?>
</table>
<a href="en_not?acao=inc">Cadastrar nova noticia</a>
en_noticia.php
<?php
$conn = mysql_connect('localhost','root','');
$db = mysql_select_db('sis_noticia');
if(!empty($_GET[id])) (
$acao = "alt";
$s_noticia = "SELECT * FROM noticia WHERE id = $_GET[id]";
$t_noticia = mysql_query($s_noticia) or die(sql_error());
$noticia = mysql_fetch_array($t_noticia);
$botao = 'Alterar';
)else(
$botao = 'Incluir';
$acao = "inc";
)
?>
<html>
<body>
<span style="font-size: 26px; font-family: verdana;">Adicionar Noticia</span>
<form action="add_not.php" method="post">
<input type="hidden" name="acao" value="<? echo $acao; ?>">
<input type="hidden" name="id" value="<? echo $noticia[id]; ?>">
<table id="form" border="1">
<tr>
<td id="span">Título:</td>
<td><input type="text" id="titulo" name="titulo" value="<? if $(acao == 'alt') echo $noticia[titulo] ?>" /></td>
</tr>
<tr>
<td id="span">Chamada:</td>
<td><textarea cols="20" rows="5" name="chamada"><? if $(acao == 'alt') echo $noticia[chamada] ?></textarea></td>
</tr>
<tr>
<td id="span">Texto:</td>
<td><textarea cols="20" rows="11" name="texto"><? if $(acao == 'alt') echo $noticia[texto] ?></textarea></td>
</tr>
</table>
<input type="submit" name="ok" value="<?php echo $botao; ?>" />
</form>
</body>
</html>
<?php
?>
E o banco de dados
//NO
//BANCO DE DADOS = SIS_NOTICIA
//CRIEI ESSA TABELA
CREATE TABLE noticia (
id INT NOT NULL AUTO_INCREMENT,
titulo VARCHAR(255) NULL,
chamada VARCHAR(255) NULL,
texto LONGTEXT NULL,
PRIMARY KEY(id)
);