ao inserir produto e alterar
ambos ficam com um pagina em branco qd clica em inserir ou alterar e nao faz nada no banco
vou postar o codigo para ver se vcs podem me ajudar ok
a tab de produto no banco ta assim
id_produto id_categoria id_subcategoria produto foto descricao preco lancamento destaque
A PAGINA LST_PRODUTO ESTA ASSIM
<?php include "conexao.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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="cat_cat"><div align="center"><strong>Lista geral de produtos </strong></div></td>
</tr>
<tr>
<td><table width="100%" border="0" cellspacing="2" cellpadding="0">
<tr>
<td width="8%" class="tarja"><strong>Código</strong></td>
<td width="39%" align="center" class="tarja"><strong>Categoria/Subcategoria</strong></td>
<td width="26%" align="center" class="tarja"><strong>Produto</strong></td>
<td width="14%" align="center" class="tarja"><strong>Preço</strong></td>
<td colspan="2" class="tarja"><div align="center"><strong>Ação</strong></div></td>
</tr>
<?php
$sql = "SELECT p.*, c.*, s.* FROM produto p, categoria c, subcategoria s WHERE p.id_categoria = c.id_categoria and p.id_subcategoria = s.id_subcategoria ORDER BY p.produto";
$qry = mysql_query($sql);
while ($linha = mysql_fetch_array($qry)){
?>
<tr>
<td align="center" class="meio"><?php echo $linha[id_produto]; ?></td>
<td class="meio"><?php echo $linha[categoria]."/".$linha[subcategoria]; ?></td>
<td class="meio"><?php echo $linha[produto]; ?></td>
<td align="center" class="meio"><?php echo $linha[preco]; ?></td>
<td width="6%" align="center" class="meio"><a href="index.php?link=7&acao=Alterar&id=<?php echo $linha[id_produto]; ?>"><img src="img/mais.png" width="16" height="16" border="0" /></a></td>
<td width="7%" align="center" class="meio"><a href="index.php?link=7&acao=Excluir&id=<?php echo $linha[id_produto]; ?>"><img src="img/deletar.png" width="16" height="16" border="0" /></a></td>
</tr>
<?php } ?>
<tr>
<td colspan="4"> </td>
<td colspan="2"><div align="right"><a href="index.php?link=7"><img src="img/inserir.jpg" width="55" height="16" border="0" /></a></div></td>
</tr>
</table></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
A PAGINA FRM_PRODUTO ESTA ASSIM
<?php
include "conexao.php";
$acao = $_GET["acao"];
$id = $_GET["id"];
$id_categoria = $_GET[id_categoria];
if ($acao != "")
{
$sql = "SELECT p.*, c.*, s.* FROM produto p, categoria c, subcategoria s WHERE p.id_categoria = c.id_categoria and p.id_subcategoria = s.id_subcategoria and p.id_produto = '$id' ";
$qry = mysql_query($sql);
$linha = mysql_fetch_array($qry);
if ($_GET["consulta"] == "sim")
{
$id_categoria = $_GET[id_categoria];
}
else
{
$id_categoria = $linha[id_categoria];
}
$id_subcategoria = $linha[id_subcategoria];
$categoria = $linha[categoria];
$subcategoria = $linha[subcategoria];
$produto = $linha[produto];
$preco = $linha[preco];
$descricao = $linha[descricao];
$lancamento = $linha[lancamento];
$detaque = $linha[destaque];
$foto = $linha[foto];
}
?>
<!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>
<script type="text/javascript" src="jscripts/tiny_mce/tiny_mce.js"></script>
<script type="text/javascript">
<!--
tinyMCE.init({
// General options
mode : "textareas",
theme : "advanced",
plugins : "safari,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template,imagemanager,filemanager",
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
theme_advanced_buttons3 : "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
theme_advanced_toolbar_location : "top",
theme_advanced_toolbar_align : "left",
theme_advanced_statusbar_location : "bottom",
theme_advanced_resizing : true,
// Example content CSS (should be your site CSS)
content_css : "css/example.css",
// Drop lists for link/image/media/template dialogs
template_external_list_url : "js/template_list.js",
external_link_list_url : "js/link_list.js",
external_image_list_url : "js/image_list.js",
media_external_list_url : "js/media_list.js",
// Replace values for the template plugin
template_replace_values : {
username : "Some User",
staffid : "991234"
}
});
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<style type="text/css">
<!--
.style2 {font-size: 20px}
-->
</style>
</head>
<body>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td><div align="center"></div></td>
</tr>
<tr>
<td><form action="op_produto.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="54%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td class="meio"><table width="403" border="0" align="center" cellpadding="2" cellspacing="0">
<tr>
<td colspan="2" align="center" bgcolor="#CCCCCC"><span class="style2">Cadastro de Produto </span></td>
</tr>
<tr>
<td width="83" bgcolor="#F5F5F5"><strong>Categoria</strong></td>
<td width="314" bgcolor="#F5F5F5"><select name= "txt_idcategoria" id="txt_idcategoria" onchange="MM_jumpMenu('parent',this,0)">
<option></option>
<?php
$sql = "SELECT * FROM categoria ORDER BY categoria";
$qry = mysql_query($sql);
while ($linha = mysql_fetch_array($qry))
{?>
<option value ="index.php?link=7&acao=<?php echo $acao; ?>&consulta=sim&id_categoria=<?php echo $linha[id_categoria]; ?>&id=<?php echo $id; ?>"<?php if ($linha[id_categoria] == $id_categoria) echo "selected"; ?>><?php echo $linha[categoria]; ?> </option>
<?php } ?>
</select></td>
</tr>
<?php if ($id_categoria !="") {?>
<tr>
<td bgcolor="#F5F5F5"><strong>SubCategoria</strong></td>
<td bgcolor="#F5F5F5"><label>
<select name="txt_idsubcategoria" id="txt_idsubcategoria">
<option value="1"> Selecione a categoria </option>
<?php
$sql_subcat = "SELECT * FROM subcategoria WHERE id_categoria = '$id_categoria' ORDER BY subcategoria";
$qry_subcat = mysql_query($sql_subcat);
while ($linha_subcat = mysql_fetch_array($qry_subcat)){
$valor = $linha_subcat[id_subcategoria];
if ($id_subcategoria == $valor)
{
$selecionado = "selected";
}
else
{
$selecionado ="";
}
print "<option value = \"$valor\" $selecionado > $linha_subcat[subcategoria] </option>";
}
?>
</select>
</label></td>
</tr>
<tr>
<td bgcolor="#F5F5F5"><strong>Produto</strong></td>
<td bgcolor="#F5F5F5"><label>
<input name="txt_produto" type="text" id="txt_produto" value="<?php echo $produto; ?>" size="50" />
</label></td>
</tr>
<tr>
<td bgcolor="#F5F5F5"><strong>Foto</strong></td>
<td bgcolor="#F5F5F5"><input name="txt_foto" type="text" id="txt_foto" value="<?php echo $foto; ?>" /></td>
</tr>
<tr>
<td bgcolor="#F5F5F5"><strong>upload</strong></td>
<td bgcolor="#F5F5F5"><input name="nome_arquivo" type="file" id="nome_arquivo" /></td>
</tr>
<tr>
<td bgcolor="#F5F5F5"><strong>preço</strong></td>
<td bgcolor="#F5F5F5"><label>
<input name="txt_preco" type="text" id="txt_preco" value="<?php echo $preco; ?>" />
</label></td>
</tr>
<tr>
<td bgcolor="#F5F5F5"><strong>Descrição</strong></td>
<td bgcolor="#F5F5F5"><label>
<textarea name="txt_descricao" cols="35" rows="6" id="txt_descricao"><?php echo $descricao; ?></textarea>
</label></td>
</tr>
<tr>
<td bgcolor="#F5F5F5"><strong>Lançamento</strong></td>
<td bgcolor="#F5F5F5"><label>
<select name="txt_lancamento" id="txt_lancamento">
<option value="S" <?php if($lancamento =="S") echo "selected"?>>Sim</option>
<option value="N" <?php if($lancamento =="N") echo "selected"?>>Não</option>
</select>
</label></td>
</tr>
<tr>
<td bgcolor="#F5F5F5"><strong>Destaque</strong></td>
<td bgcolor="#F5F5F5"><label>
<select name="txt_destaque" id="txt_destaque">
<option value="S" <?php if($destaque =="S") echo "selected"?>>Sim</option>
<option value="N" <?php if($destaque =="N") echo "selected"?>>Não</option>
</select>
</label></td>
</tr>
<tr>
<td bgcolor="#F5F5F5"> </td>
<td bgcolor="#F5F5F5"> </td>
</tr>
<tr>
<td colspan="2" bgcolor="#F5F5F5"><div align="center">
<input type="submit" name="Submit" value="<?php if ($acao !="") {echo $acao;} else { echo "Inserir";} ?>" />
<input name="acao" type="hidden" id="acao" value="<?php if ($acao !="") {echo $acao;} else { echo "Inserir";} ?>" />
<input name="id" type="hidden" id="id" value="<?php echo $id; ?>" />
<input name="txt_idcategoria" type="hidden" id="txt_idcategoria" value="<?php echo $id_categoria; ?>" />
</div></td>
</tr>
<?php } ?>
</table></td>
</tr>
</table>
</form>
</td>
</tr>
<tr>
<td> </td>
</tr>
</table>
</body>
</html>
A PAGINA OP_PRODUTO ESTA ASSIM
<?php include "conexao.php";
$acao = $_POST["acao"];
$id = $_POST["id"];
$txt_subcategoria = $_POST["txt_subcategoria"];
$txt_idcategoria = $_POST["txt_idcategoria"];
$txt_id_subcategoria = $_POST["txt_idsubcategoria"];
$txt_categoria = $_POST["txt_categoria"];
$txt_subcategoria = $_POST["txt_subcategoria"];
$txt_produto = $_POST["txt_produto"];
$txt_foto = $_POST["txt_foto"];
$txt_destaque = $_POST["txt_destaque"];
$txt_preco = $_POST["txt_preco"];
$txt_descricao = $_POST["txt_descricao"];
$txt_lancamento = $_POST["txt_lancamento"];
if ( $acao=="Inserir" )
{
//verifica a foto
$arquivo = isset($_FILES["foto"]) ? $_FILES["foto"] : FALSE;
$config = array();
$config["tamanho"] = 106883;
$config["largura"] = 400;
$config["altura"] = 250;
$config["diretorio"] = "fotos/";
function nome($extensao)
{
global $config;
$temp = substr(md5(uniqid(time())), 0, 10);
$imagem_nome = $temp . "." . $extensao;
if(file_exists($config["diretorio"] . $imagem_nome))
{
$imagem_nome = nome($extensao);
}
return $imagem_nome;
}
if($arquivo)
{
$erro = array();
if(!eregi("^image\/(pjpeg|jpeg|png|gif|bmp)$", $arquivo["type"]))
{
$erro[] = "Arquivo em formato inválido! A imagem deve ser jpg, jpeg, bmp, gif ou png. Envie outro arquivo";
}
else
{
if($arquivo["size"] > $config["tamanho"])
{
$erro[] = "Arquivo em tamanho muito grande! A imagem deve ser de no máximo " . $config["tamanho"] . " bytes. Envie outro arquivo";
}
$tamanhos = getimagesize($arquivo["tmp_name"]);
if($tamanhos[0] > $config["largura"])
{
$erro[] = "Largura da imagem não deve ultrapassar " . $config["largura"] . " pixels";
}
if($tamanhos[1] > $config["altura"])
{
$erro[] = "Altura da imagem não deve ultrapassar " . $config["altura"] . " pixels";
}
}
if(!sizeof($erro))
{
preg_match("/\.(gif|bmp|png|jpg|jpeg){1}$/i", $arquivo["name"], $ext);
$imagem_nome = nome($ext[1]);
$imagem_dir = $config["diretorio"] . $imagem_nome;
// Faz o upload da imagem
move_uploaded_file($arquivo["tmp_name"], $imagem_dir);
}
elseif(sizeof($erro))
{
echo "<tr><td colspan=2 bgcolor=red><B><U>Ocorreu(am) o(s) seguinte(s) erro(s):</u><BR>";
foreach($erro as $err)
{
echo " - " . $err . "<BR>";
}
echo "</B></td></tr>";
}
}
//se der tudo certo
if($arquivo && !sizeof($erro))
{
$txt_foto = $imagem_nome;
$sql = "INSERT INTO produto(
id_categoria, id_subcategoria, produto, foto, descricao, destaque, preco, lancamento)
VALUES
('$txt_idcategoria', '$txt_idsubcategoria', '$txt_produto', '$txt_foto', '$txt_descricao', '$txt_destaque', '$txt_preco', '$txt_lancamento')";
print $sql;
mysql_query($sql) or die ("não foi possível inserir dados");
print "<script type = 'text/javascript'> location.href = 'index.php?link=6'</script>";
}
}
if ($acao==Alterar )
{
$sql = "UPDATE produto SET
id_categoria = '$txt_idcategoria',
id_subcategoria = '$txt_idsubcategoria',
produto = '$txt_produto',
descricao = '$txt_descricao',
destaque = '$txt_destaque',
foto = '$txt_foto',
preco = '$txt_preco',
lancamento = '$txt_lancamento'
WHERE id_produto = '$id' ";
print($sql);
mysql_query ($sql) or die ("não foi possível alterar os dados");
print "<script type = 'text/javascript'> location.href = 'index.php?link=6'</script>";
}
if ($acao==Excluir)
{
$sql = "DELETE FROM produto WHERE id_produto = $id";
mysql_query($sql);
print "<script type = 'text/javascript'> location.href = 'index.php?link=6'</script>";
}
?>












