Codigo:
[codebox]<?php
include "../includes/conecta.php";
$sql_categoria = mysql_query("select * from categoria", $db);
$titulo = $_POST['titulo'];
$subtitulo = $_POST['subtitulo'];
$categoria = $_POST['categoria'];
$data = date("Y-m-d");
$destaque = $_POST['destaque'];
$noticia = $_POST['noticia'];
$fonte = $_POST['fonte'];
$diretorio = "../imgs/noticias/";
$imagem = '';
if( isset( $_FILES['imagem'] ) )
{
// enviou imagem
$imagem = $_FILES['imagem']['name'];
if(move_uploaded_file($_FILES['imagem']['tmp_name'], $diretorio . $imagem )) {
// enviou imagem. aparentemente, sem problema
}else{
// enviou imagem mas algum problema ocorreu
$imagem = '';
}
}else{
// não enviou imagem
}
$sql = mysql_query("insert into noticias (titulo, subtitulo, categoria, data, destaque, noticia, fonte, imagem) VALUES ('$titulo', '$subtitulo', '$categoria', '$data', '$destaque', '$noticia', '$fonte', '$imagem')") or die ("Erro na Consulta: ".mysql_error());
if ($sql ) {
echo "Cadastro de notícia efetuado.";
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<table width="100%" border="0">
<tr>
<td> </td>
</tr>
</table>
<table width="100%" border="0">
<tr>
<td width="22%" valign="top"> </td>
<td width="78%" valign="top"><table width="100%" border="0">
<tr>
<td> </td>
</tr>
</table>
<form action="cadastronoticia.php" method="post" enctype="multipart/form-data" name="noticia">
<table width="100%" border="0">
<tr>
<td width="17%">Titulo:</td>
<td width="83%"><input type="text" name="titulo" size="40" id="titulo" /></td>
</tr>
<tr>
<td>Subtitulo:</td>
<td><input type="text" name="subtitulo" size="40" maxlength="150" /></td>
</tr>
<tr>
<td>Categoria:</td>
<td><select name="categoria">
<option value="0"><
<Selecione o tipo>
></option>
<?php while($array = mysql_fetch_array($sql_categoria)) {?>
<option value="<?php echo $array['2']; ?>"><?php echo $array['1']; ?></option>
<?php } ?>
</select></td>
</tr>
<tr>
<td>Destaque:</td>
<td><select name="destaque">
<option value="1">Sem destaque</option>
<option value="2"> Destacar</option>
</select></td>
</tr>
<tr>
<td>Notícia:</td>
<td><textarea name="noticia" cols="50" rows="15" id="noticia"></textarea></td>
</tr>
<tr>
<td>Fonte</td>
<td><input type="text" name="fonte" size="40" id="fonte" /></td>
</tr>
<tr>
<td>Imagem:</td>
<td><input type="file" name="imagem" /></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Cadastrar" />
-
<input type="reset" value="Limpar dados" /></td>
</tr>
</table>
</form></td>
</tr>
</table>
</body>
</html>[/codebox]
Edição feita por: savior, 26/04/2009, 19:07.