Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa noite,
Estou a desenvolver um formulario em php, onde este envia para a base dados os dados do formulário, no entanto dá-me um erro...
Gostaria de expôr aqui o meu caso para que se possivel me ajudem...
O respectivo formulário está no meu localhost... atraves do xampp.
tenho um ficheiro cadastra_post.php
-------------------------------------------------------------------------------------------------------------------
<?php include "config.php";?>
<!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">](http://www.w3.org/1999/xhtml)
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cadastrar Postagem</title>
<link rel="stylesheet" type="text/css" href="scripts/css.css"/>
</head>
<body>
<div id="conteudo">
<table width="809" height="443" border="1">
<tr>
<th width="148" scope="col">Menu</th>
<th width="645" scope="col">Corpo</th>
</tr>
<tr>
<td height="412"> </td>
<td>
<?php if(isset($_POST['cadastrar_posts']) && $_POST['cadastrar_posts'] == 'cad'){
$img=$_FILES['foto'];
$titulo=$_POST['titulo'];
$texto=$_POST['texto'];
$autor=$_POST['autor'];
$categoria=$_POST['categoria'];
$data=$_POST['data'];
$pasta="../upload/post";
$permitido = array('image/jpg','image/jpeg','image/pjpeg');
require ("scripts/funcao_upload.php");
$nome = $img['name'];
$tmp = $img['tmp_name'];
$type = $img['type'];
if (!empty($nome)&& in_array($type, $permitido)){
$name = md5(uniqid(rand(), true)).".jpg";
Redimensionar($tmp,$name, 390, $pasta);
$cadastrar_noticias = mysql_query("INSERT INTO site_posts(foto, titulo, texto, categoria, data, autor, visitas)
VALUES('$name', '$titulo', '$texto', '$categoria', '$data', '$autor', '1')")
or die (mysql_error());
}
}
?>
<form name="cadastrar_posts" id="cadastrar_posts" method="post" action="" enctype="multipart/from-data">
<fieldset>
<p>
<label>
<span>Imagem a ser exibida</span>
<input type="file" name="foto" size="50"/>
</label>
<label>
<span>titulo da postagem</span>
<input type="text" name="titulo"/>
</label>
<label>
<span>Texto</span>
<textarea name="texto" rows="5">
</textarea>
</label>
<label>
<span>Autor</span>
<input type="text" name="autor"/>
</label>
<label>
<span>Categorias</span>
<select name="categoria" id="categoria">
<option value="">Selecione uma categoria</option>
<option value="noticias" id="noticias">Noticias</option>
<option value="eventos" id="eventos">Eventos</option>
<option value="especiais" id="especiais">Especiais</option>
<option value="desporto" id="desporto">Desporto</option>
</select>
</label>
<label>
<span>Data</span>
<input type="text" name="data" value="<?php echo date('d/m/Y');?>"/>
</label>
<input type="hidden" name="cadastrar_posts" value="cad"/>
</p>
<p>
<input type="submit" value="Cadastrar" name="Cadastrar" class="cadastro_btn" />
</p>
</fieldset>
</form>
</td>
</tr>
</table>
</div>
</body>
</html>
-----------------------------------------------------
O respectivo config.php
<?php
$db = mysql_connect("localhost","root","");
$dados = mysql_select_db ("portal",$db);
?>
------------------------------------------------
e outro funcao_upload.php
<?php
function Redimensionar($tmp, $name, $largura, $pasta){
$img = imagecreatefromjpeg($tmp);
$x = imagesx($img);
$y = imagesy($img);
$altura = ($largura*$y) / $x;
$nova = imagecreatetruecolor($largura, $altura);
imagecopyresampled($nova, $img, 0, 0, 0, 0, $largura, $altura, $x, $y);
imagejpeg($nova, "$pasta/$name");
imagedestroy($img);
imagedestroy($nova);
return($name);
}
?>
-------------------------------------------
Quando acedo ao formulário através do meu localhost surge-me então o seguinte erro:
Notice: Undefined index: foto in C:\xampp\htdocs\portal\admin\cadastra_post.php on line 21
Sendo que não actualiza os dados na base dados, nem o ficheiro de imagem é devolvido para a respectiva pasta no localhost...
Alguem me pode ajudar.. ou solucionar de forma diferente ...
Carregando comentários...