jazz jazz - 4 months ago 7
MySQL Question

How to submit values from form

I have a form that is being created dynamically

<form action="addtable.php" method="post" enctype="multipart/form-data" >
<?php
$sql="SELECT * FROM `tracker_item` ";
$result = mysqli_query($con, $sql);
if(mysqli_num_rows($result)>0)
{
while($row = mysqli_fetch_assoc($result))
{ ?>
<input type="text" placeholder="<? echo $row['heading']?>" name="<? echo $row['heading']?>" />

<?}?>
<button type="submit" name="add" alt="Add" value="Add" class="btn blue">Add</button>
</form>


But i a not able to understand how to carry the value of input to the addtable.php page

Can anyone please tell how to submit these values from this form

Answer

In your addtable.php, you need to print_r $_POST and see what inputs you're getting.

// addtable.php

echo "<pre>";
print_r($_POST);
print_r($_FILES);  // If you're expecting a file input

Also, you should modify your HTML a little:

<form action="addtable.php" method="post" enctype="multipart/form-data" >
<?php
$sql="SELECT * FROM `tracker_item` ";
$result = mysqli_query($con, $sql);
if(mysqli_num_rows($result)>0) {
        while($row = mysqli_fetch_assoc($result)) { ?>
          <input type="text"  placeholder="<? echo $row['heading']?>" name="<? echo $row['heading']?>" />
        <? }  ?>
    <button type="submit" name="add" alt="Add" value="Add" class="btn blue">Add</button>      <!--Place submit button outside loop -->
<?php } ?>