0

The form here show input if a value is verified by the user, therefore a dynamic form field is required:

<form class="form-horizontal"  method="POST" action="ajouterProduit4" name="formulaire">                
<div class="panel panel-default tabs">                            
<ul class="nav nav-tabs" role="tablist">
	<li class="active"><a href="ajouterProduit2"><button name="btn2" style="background: transparent; border: none;">Fiche Technique</button></a></li>
	
</ul>
<div class="panel-body tab-content">
											
	<div class="tab-pane active" id="tab-second">
	
		<?php 
			$reqt1 = "SELECT c.Libelle,c.ID FROM caracteristique c,fichetechnique f WHERE c.fichetechniqueID=f.ID AND c.fichetechniqueID='$categorie' LIMIT 0,10";
			$reqt2 = "SELECT c.Libelle,c.ID FROM caracteristique c,fichetechnique f WHERE c.fichetechniqueID=f.ID AND c.fichetechniqueID='$categorie' LIMIT 10,10";
			$rest1=mysqli_query($conne,$reqt1);
			$rest2=mysqli_query($conne,$reqt2);
		?>
		<div class="col-md-6" id="txtHint">
			<?php
				while ($rowt1= mysqli_fetch_row($rest1)) {
			?>
			<div class="form-group">
				<label class="col-md-3 control-label"><?php echo $rowt1[0] ?></label>
				<div class="col-md-9">                                            
					<div class="input-group">
						<span class="input-group-addon"><span class="fa fa-pencil"></span></span>
						<input  name="rowt1"   type="text" class="form-control" />
						
					</div>                                            
					
				</div>
			</div> 
				<?php }  ?>
		</div>
		
		<div class="col-md-6">
			<?php
				while ($rowt2= mysqli_fetch_row($rest2)) {
			?>
		<div class="form-group">
			<label class="col-md-3 control-label"><?php echo $rowt2[0] ?></label>
			<div class="col-md-9">                                            
				<div class="input-group">
					<span class="input-group-addon"><span class="fa fa-pencil"></span></span>
					<input name="rowt2" type="text" class="form-control"/>
				</div>                                            
			</div>
		</div>
			<?php } ?>
		</div>
	   
	</div>                                        
   
</div>
			<div class="panel-footer">
				<input type="reset" class="btn btn-default" value="Réinitialiser">
				<button name="envoyer" class="btn btn-primary pull-right">Etape 3 <span class="fa fa-arrow-right fa-right"></span></button>
			</div>	
</div>

</div>                                
							
</form>

However, I don't know how to go about inserting data into the database when it is not clear what the data may be (specifically the category)

In pseudocode it would be ("INSERT INTO Category(Value) values ($value)")

N.B: I only use procedural php

2
  • Your inputs does not contain value='??' Commented Jul 9, 2016 at 15:44
  • Why you are exexuting 2 times the same query? Commented Jul 9, 2016 at 15:47

2 Answers 2

1

You can generate the form dynamically using HTML input array.

<?php $fruits = ['apple', 'orange', 'strawberry', 'pear'] ?>

<form method="POST" action="action.php">
    <?php for ($i=0; $i < count($fruits); $i++): ?>
        <input type="text" name="fruits[<?php echo $i ?>]" value="<?php echo $fruits[$i] ?>" />
    <?php endfor ?>
    <input type="submit" value="Submit" />
</form>

On the example above, you generate an input type with name fruits. Then, you submit the form into action.php (see the code below).

<?php

$fruits = $_POST['fruits'];
var_dump($fruits);

And the result, when you run it on the browser is below.

array (size=4)
  0 => string 'apple' (length=5)
  1 => string 'orange' (length=6)
  2 => string 'strawberry' (length=10)
  3 => string 'pear' (length=4)

Hope it helps.

Sign up to request clarification or add additional context in comments.

Comments

0

Use this form :

<form class="form-horizontal"  method="POST" action="ajouterProduit4" name="formulaire">                
<div class="panel panel-default tabs">                            
<ul class="nav nav-tabs" role="tablist">
    <li class="active"><a href="ajouterProduit2"><button name="btn2" style="background: transparent; border: none;">Fiche Technique</button></a></li>

</ul>
<div class="panel-body tab-content">

    <div class="tab-pane active" id="tab-second">

        <?php 
            $reqt1 = "SELECT c.Libelle,c.ID FROM caracteristique c,fichetechnique f WHERE c.fichetechniqueID=f.ID AND c.fichetechniqueID='$categorie' LIMIT 0,10";
            $reqt2 = "SELECT c.Libelle,c.ID FROM caracteristique c,fichetechnique f WHERE c.fichetechniqueID=f.ID AND c.fichetechniqueID='$categorie' LIMIT 10,10";
            $rest1=mysqli_query($conne,$reqt1);
            $rest2=mysqli_query($conne,$reqt2);
        ?>
        <div class="col-md-6" id="txtHint">
            <?php
                while ($rowt1= mysqli_fetch_row($rest1)) {
            ?>
            <div class="form-group">
                <label class="col-md-3 control-label"><?php echo $rowt1[0] ?></label>
                <div class="col-md-9">                                            
                    <div class="input-group">
                        <span class="input-group-addon"><span class="fa fa-pencil"></span></span>
                        <input  name="rowt1[]" value="<?php echo $rowt1[1]; ?>" type="text" class="form-control" />

                    </div>                                            

                </div>
            </div> 
                <?php }  ?>
        </div>

        <div class="col-md-6">
            <?php
                while ($rowt2= mysqli_fetch_row($rest2)) {
            ?>
        <div class="form-group">
            <label class="col-md-3 control-label"><?php echo $rowt2[0] ?></label>
            <div class="col-md-9">                                            
                <div class="input-group">
                    <span class="input-group-addon"><span class="fa fa-pencil"></span></span>
                    <input name="rowt2[]" value="<?php echo $rowt2[1]; ?>" type="text" class="form-control"/>
                </div>                                            
            </div>
        </div>
            <?php } ?>
        </div>

    </div>                                        

</div>
            <div class="panel-footer">
                <input type="reset" class="btn btn-default" value="Réinitialiser">
                <button name="envoyer" class="btn btn-primary pull-right">Etape 3 <span class="fa fa-arrow-right fa-right"></span></button>
            </div>  
</div>

</div>                                

</form>

In the server side:

<?php 
$rowt1=$_REQUEST['rowt1'];// will return post array due to the declaration in the form as rowt1[]
$rowt2=$_REQUEST['rowt2'];// will return post array due to the declaration in the form as rowt2[]
foreach ($rowt1 as $key => $value) {
    $sql="INSERT INTO TABLENAME1 ('rowt1') VALUES ('".$value."')";
    // run the query
}
foreach ($rowt2 as $key => $value) {
    $sql="INSERT INTO TABLENAME2 ('rowt2') VALUES ('".$value."')";
    // run the query
}
?>

Hope this may solve your problem. Thanks.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.