Registro de noticias com foto
bom dia,
estou com dificuldades de cadastrar uma noticia com foto no banco de dados., No caso a noticia é cadastrada mas a foto em anexo nao... peço a ajuda de voce para poder resolver isso... vou postar o codigo..
Obs, não sei utilizar o[ code ] então vai normal mesmo...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<link type="text/css" rel="stylesheet" href="sistema.css" />
<script language="javascript">
//aqui faz a função de abrir e fechar a div para colocar foto ou não
function mudaDiv() {
var div = document.getElementById("teste");
var check = document.getElementById("check");
if (check.checked) {
div.className = "aparece";
} else {
div.className = "some";
}
}
</script>
<style>
.aparece {display: block;}
.some {display: none;}
body {
margin-left: 15px;
}
</style>
<?php require("conexao.php"); ?>
</head>
<body>
<p><?
if ($_GET['vai'] == 'envia'){
mysql_query("select * from noticias");
////////////////////////////////
$titulo = $_POST['titulo'];
$subtitulo = $_POST['subtitulo'];
$texto = $_POST['texto'];
if(file_exists ($foto01)){ $teste01 = date('dmy') . '-' . date('His') . '-' .$_FILES['foto01']['name']; }
//////////////////////////////////
//aqui faz a liberação ou não dos inputs//
if($titulo == "")
{
echo" ** Por Favor Preencha o Campo Titulo! **";
}
else if($subtitulo == ""){
echo" ** Por Favor Preencha uam Descrição para a notícia! **";
}
else if($texto == ""){
echo" ** Por Favor Preencha o Campo Texto! **";
}
else
{
// cadastra nos bancos //
$envia =mysql_query("insert into noticias(data,hora,titulo,subtitulo,texto,foto01) values ('$data','$hora','$titulo','$subtitulo','$texto','$teste01')")or die(mysql_error());
if($foto01_name){
copy($foto01,$teste01);
}
echo "Notícia Cadastrada com Sucessos!";
}
}
?>
</p>
<h1 class="admin-2">:: Cadastro de Noticias :: </h1>
<form action="?vai=envia" name="form Noticías" enctype="multipart/form-data" method="post">
<input name="data" type="hidden" class="form" value="<?=$data = date("Y-m-d");?>" /><br />
<input name="hora" type="hidden" class="form" value="<?=$hora = date("H:i:s");?>" />
<label>Título da Notícia: </label><input name="titulo" type="text" class="form" size="60" />
<br />
<br />
<label>Descrição da Notícia: </label><input name="subtitulo" type="text" class="form" size="60" />
<br />
<br />
<label>Texto:</label>
<textarea name="texto" class="form" style="width: 300px; height: 100px;">
</textarea>
<br />
<span class="admin-link-1">
<label>Com Fotos:</label>
</span>
<input type="checkbox" id="check" onclick="mudaDiv()"/>
<br />
<div id="teste" class="some">
<label>Imagem:</label> <input type="file" name="foto01" class="form" /><br />
</div><br />
<label> </label><input type="submit" value="Enviar" class="form" />
</form>
</body>
</html>
aguardo alguma resposta que consiga resolver isso para mim...
abraço a todos.
Discussão (12)
Carregando comentários...