subcategory and category registration

Asked

Viewed 34 times

0

Good afternoon I have a problem that I am not being able to register category and subcategory in the product table in my database has a column that calls id_subcategory and another id_category and I need to show the id of the subcategory and category in these tables. This id comes from another table called category and subcategory.

<?php
require_once 'sessao.php';
require_once 'connection.php';

$stmt = $conexao->query('select * from categoria');
$categorias = $stmt->fetchAll(PDO::FETCH_OBJ); 
?>

<html>
 <head>
   <meta charset="UTF-8" />
     <script src="js/jquery-1.10.1.min.js"></script>
<script src="js/busca_categoria.js"></script>
<script src="../ckeditor.js"></script>
 </head>
    <body>
        
        
     <form action="produto.php" method="post" enctype="multipart/form-data">
       	 Categoria:<br>
	    <select name="categoria" id="categoria">
	    	<option value="">Selecione Uma Opcao</option>

	    	 <?php foreach ($categorias as $categoria ): ?>
                 <option value="<?php echo $categoria->id_categoria;?>"><?php echo $categoria->tx_nome;?></option>
             <?php endforeach ?>
	    	
	    </select>

    <br><br>

	Subcategoria:<br>
     <select name="subcategoria" id="subcategoria">

     </select>
        <input type="file" name="file_img[]" multiple />
         <input type="submit" name="btn_upload" value="Upload" />
     </form>
        
        
        
        
        
        <?php 
         if(isset($_POST['btn_upload']))
         {
             
             $con = mysqli_connect("localhost","otimi314_imagens","WkJJu336@otimi","otimi314_naoapagar");
             
             for($i=0; $i<count($_FILES["file_img"]["name"]); $i++)
             {
                 $filetmp = $_FILES["file_img"]["tmp_name"][$i];
                 $filename = $_FILES["file_img"]["name"][$i];
                 $filetype = $_FILES["file_img"]["type"][$i];
                 $filepath = "imagens/fotos/" .$filename;
                 
                 
                 move_uploaded_file($filetmp,$filepath);
                 $sql = "INSERT INTO produto (tx_imagem,img_path,img_type,id_subcategoria,id_categoria) VALUES ('$filename', '$filepath', '$filetype', 'id_subcategoria','id_categoria')";
                 
                  
                 mysqli_query($con, $sql);
                 

                 
  
             }
             
             
         }
   
        ?>
        
        
    </body>
</html>

  • Vinicius seems to me that you do not bring in your code the selection of the subcategory. You run a foreach for categories, but would need based on this, select the subcategory check?

  • Hello Renato!! No, what I’m not getting is to register in the database, category and subcategory.

  • I already have the code pulling the select from the subcategory

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.