Unconfigured Ad Widget

Collapse

Anúncio

Collapse
No announcement yet.

Ajudem - Erro curso Mjailton criando uma loja virtual

Collapse
X
 
  • Filter
  • Tempo
  • Show
Clear All
new posts

  • Font Size
    #1

    Duvida Ajudem - Erro curso Mjailton criando uma loja virtual

    Galera seguinte estou seguindo o curso o Mjailton criando uma loja virtual completa, ja fiz e refiz e ja conferi com o codigo que ele mandou no dvd pra mim.

    na parte de cadastro de produtos ele usa os arquivos lst_produto (listar) frm_produto (formulario para alterar / excuir / inserir) e op_produtos que faz toda a operação

    primeira vez que posto algo aqui entao nao sei como faço para colocar o codigo se eu errar me desculpem

    o erro é: quando clica em inserir um novo produto ele pede para vc selecionar a categoria que ele esta e te da as opções de subcategorias cadastradas, ate ai td certo sem erro mas no proximo passa quando preencho td e clico em inserir ele vai para a pag op_produto e fica td em branco, nao consigo fazer a alteração e nem inserir nada (somente consigo exlcuir)

    vou postar o codigo se alguem puder me ajudar so falta isso pra eu resolver

    Código:
    PAGINA LST_PRODUTO
    
    <?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&oacute;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&ccedil;o</strong></td>
            <td colspan="2" class="tarja"><div align="center"><strong>A&ccedil;&atilde;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";
    			//echo $sql;
    			$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&amp;acao=Alterar&amp;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&amp;acao=Excluir&amp;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">&nbsp;</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>&nbsp;</td>
      </tr>
    </table>
    </body>
    </html>
    PÁGINA FRM_PRODUTO
    <?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,s ave,advhr,advimage,advlink,emotions,iespell,inline popups,insertdatetime,preview,media,searchreplace, print,contextmenu,paste,directionality,fullscreen, noneditable,visualchars,nonbreaking,xhtmlxtras,tem plate,imagemanager,filemanager",

    // Theme options
    theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,striketh rough,|,justifyleft,justifycenter,justifyright,jus tifyfull,|,styleselect,formatselect,fontselect,fon tsizeselect",
    theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,search,repla ce,|,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,s up,|,charmap,emotions,iespell,media,advhr,|,print, |,ltr,rtl,|,fullscreen",
    theme_advanced_buttons4 : "insertlayer,moveforward,movebackward,absolute,|,s tyleprops,spellchecker,|,cite,abbr,acronym,del,ins ,attribs,|,visualchars,nonbreaking,template,blockq uote,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&amp;acao=<?php echo $acao; ?>&amp;consulta=sim&amp;id_categoria=<?php echo $linha[id_categoria]; ?>&amp;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&ccedil;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&ccedil;&atilde;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&ccedil;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&atilde;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&atilde;o</option>
    </select>
    </label></td>
    </tr>
    <tr>
    <td bgcolor="#F5F5F5">&nbsp;</td>
    <td bgcolor="#F5F5F5">&nbsp;</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>&nbsp;</td>
    </tr>
    </table>
    </body>
    </html>
    PÁGINA OP_PRODUTO

    Código HTML:
    <?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>";
      
    }
    
    ?>

  • Font Size
    #2
    código correto e funcionando

    Amigão,

    Segue corrigido.

    FRM_PRODUTO.PHP

    <?php
    include "conexao.php";
    require "funcao.php";

    $acao = $_GET["acao"];
    $id = $_GET["id"];
    $id_categoria = $_GET[id_categoria];

    if ($acao != "")
    {
    $sql = "SELECT p.*, c.*, s.* FROM produtos 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];
    $preco1 = $linha[preco1];
    $descricao = $linha[descricao];
    $lancamento = $linha[lancamento];
    $foto = $linha[foto];
    $estoque = $linha[estoque];
    $parcela = 12;


    }

    ?>

    <!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" />
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title> croclaro.com </title>
    <link href="estilo-admin.css" type = "text/css" rel="stylesheet" media="all" >
    <script type="text/javascript">
    function MM_jumpMenu(targ,selObj,restore){ //v3.0
    eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
    if (restore) selObj.selectedIndex=0;
    }
    //-->
    </script>



    </head>
    <body>
    <div id="box-cadastro">
    <div id="formulario-menor">
    <form id ="form1" name="form1" method="post" enctype="multipart/form-data" action="op_produto.php" >
    <fieldset>
    <legend> Cadastro de produtos</legend>
    <label>
    <span> Categoria</span>
    <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 ="principal.php?link=16&acao=<?php echo $acao; ?>&amp;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>
    <?php if ($id_categoria !="") {?>
    </label>
    <label>
    <span> SubCategoria</span>
    <select name="txt_idsubcategoria" id="txt_idsubcategoria">
    <option value="1"> Selecione a SubCategoria </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>
    <label>
    <span> Produto</span>
    <input type = "text" name="txt_produto" id="txt_produto" value ="<?php echo $produto; ?>">
    </label>
    <label>

    <span> Foto</span>
    <?php if ($acao=="" ){ ?>
    <input type="file" size="30" name="foto" />
    <?php } else { ?>
    <input type = "text" name="txt_foto" id="txt_foto" value ="<?php echo $foto; ?>">
    <?php } ?>
    </label>
    <label>
    <span> Estoque</span>
    <input type = "text" name="txt_estoque" id="txt_estoque" value ="<?php echo $estoque; ?>">
    </label>
    <label>
    <span> Preço De:</span>
    <input type = "text" name="txt_preco" id="txt_preco" value ="<?php echo $preco; ?>">
    </label>
    <label>
    <span> Preço Por:</span>
    <input type = "text" name="txt_preco1" id="txt_preco1" value ="<?php echo $preco1; ?>">
    </label>
    <label>
    <span> Descrição</span>

    <textarea name="txt_descricao" cols="36" rows="5" id="txt_descricao"><?php echo $descricao; ?></textarea>
    </label>
    <label>
    </label>
    <label>
    <span> Lancamento</span>
    <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>

    <input type="hidden" name ="id" value="<?php echo $id; ?>">
    <input type="hidden" name ="acao" value="<?php if ($acao!=""){echo $acao;}else{echo "Inserir";} ?>">
    <input type="submit" name= "logar" id="logar" value = "<?php if ($acao!=""){echo $acao;}else{echo "Inserir";} ?>" class="botao" >
    <input name="txt_idcategoria" type="hidden" id="txt_idcategoria" value="<?php echo $id_categoria; ?>" />

    </fieldset>
    <?php } ?>
    </form>
    </div>
    </div>
    </body>
    </html>

    OP_PRODUTO.PHP

    <?php include "conexao.php";

    $acao = $_POST["acao"];
    $id = $_POST["id"];
    $foto = $_POST['foto'];

    $id_categoria = $_POST["id_categoria"];
    $id_subcategoria = $_POST["id_subcategoria"];
    $txt_subcategoria = $_POST["txt_subcategoria"];
    $txt_idcategoria = $_POST["txt_idcategoria"];
    $txt_idsubcategoria = $_POST["txt_idsubcategoria"];
    $txt_categoria = $_POST["txt_categoria"];
    $txt_subcategoria = $_POST["txt_subcategoria"];
    $txt_produto = $_POST["txt_produto"];
    $txt_foto = $_POST["txt_foto"];
    $txt_preco = $_POST["txt_preco"];
    $txt_preco1 = $_POST["txt_preco1"];
    $txt_descricao = $_POST["txt_descricao"];
    $txt_lancamento = $_POST["txt_lancamento"];
    $txt_estoque = $_POST["txt_estoque"];


    // ------------------ INÍCIO VALIDAÇÃO CADASTRO DE PRODUTOS ------------------//

    if ($txt_idcategoria==""){
    print "Campo CATEGORIA está vazio... favor preencher...";
    }
    elseif ($txt_idsubcategoria==""){
    print "Campo SUBCATEGORIA está vazio... favor preencher...";
    }
    elseif ($txt_produto==""){
    print "Campo PRODUTO está vazio... favor preencher...";
    }
    elseif ($txt_estoque==""){
    print "Campo ESTOQUE está vazio... favor preencher...";
    }
    elseif (!is_numeric($txt_estoque)){
    print "Campo ESTOQUE aceita apenas números... favor preencher...";
    }
    elseif ($txt_preco==""){
    print "Campo PREÇO De: está vazio... favor preencher...";
    }
    elseif ($txt_preco1==""){
    print "Campo PREÇO Por: está vazio... favor preencher...";
    }
    elseif (!is_numeric($txt_preco)){
    print "Campo PREÇO aceita apenas números... favor preencher...";
    }
    elseif ($txt_descricao==""){
    print "Campo DESCRIÇÃO está vazio... favor preencher...";
    }
    elseif ($txt_lancamento==""){
    print "Campo LANÇAMENTO está vazio... favor preencher...";
    }

    // ------------------------- FIM VALIDAÇÃO DO FORMULÁRIO CADASTRO DE PRODUTOS ----------------//

    elseif ($acao=="Inserir")
    {

    // ------------------ INÍCIO DO CÓDIGO INSERIR ------------------//

    //verificação das imagens
    $arquivo = isset($_FILES["foto"]) ? $_FILES["foto"] : FALSE;

    $config = array();
    $config["tamanho"] = 1068883;
    $config["largura"] = 350;
    $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[] = "Campo FOTO está vazio ... favor preencher no formato correto ...a imagem deve ser jpg, jpeg, bmp, gif ou png...";
    }

    else
    {
    if($arquivo["size"] > $config["tamanho"])
    {
    $erro[] = "Arquivo maior que o permitido, a imagem deve ser no máximo" . $config["tamanho"]."bytes";
    }
    $tamanhos = getimagesize ($arquivo["tmp_name"]);

    if($tamanho[0] > $config["largura"])
    {
    $erro[] = "Largura maior que a permitida, a largura deve ser no mximo" . $config["largura"] . "pixels";
    }
    if($tamanho[1] > $config["altura"])
    {
    $erro[] = "Altura maior que a permitida, a largura deve ser no mximo" . $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;

    move_uploaded_file($arquivo["tmp_name"], $imagem_dir);

    }

    }

    if ($arquivo && !sizeof($erro))
    {
    $txt_foto = $imagem_nome;

    $sql = "INSERT INTO produtos(

    id_categoria, id_subcategoria, produto, foto, descricao, estoque, preco, preco1, lancamento)

    VALUES

    ('$txt_idcategoria', '$txt_idsubcategoria', '$txt_produto', '$txt_foto', '$txt_descricao', '$txt_estoque', '$txt_preco', '$txt_preco1', '$txt_lancamento')";

    mysql_query($sql) or die (mysql_error());

    header ("locationrincipal.php?link=16");

    }
    else
    {
    if(sizeof($erro))
    {
    echo "Ocorreram os seguintes erros:";
    foreach($erro as $err)
    {
    echo " " .$err ."<br>";
    }
    echo "</br>";
    }
    }
    }

    // ------------------ FIM DO CÓDIGO INSERIR ------------------//

    if ($acao==Alterar )
    {
    $sql = "UPDATE produtos SET

    id_categoria = '$txt_idcategoria',
    id_subcategoria = '$txt_idsubcategoria',
    produto = '$txt_produto',
    foto = '$txt_foto',
    descricao = '$txt_descricao',
    estoque = '$txt_estoque',
    preco = '$txt_preco',
    preco1 = '$txt_preco1',
    lancamento = '$txt_lancamento'



    WHERE id_produto = '$id' ";

    mysql_query ($sql) or die ("não foi possível alterar os dados");

    header ("locationrincipal.php?link=16");
    }

    if ($acao==Excluir)

    {
    $sql = "DELETE FROM produtos WHERE id_produto = $id";

    mysql_query($sql);
    print "<script type = 'text/javascript'> location.href = 'principal.php?link=16'</script>";

    }

    ?>

    Comment


    • Font Size
      #3
      Código completo da Loja

      Bom dia amigos.
      Seria possível disponibilizar o código completo da loja para download?

      Obrigado

      Comment

      X
      Working...
      X