-1

I have a html table with multiple rows with dynamic Id and name assigned. I want to retrieve the rows values in php. When I am doing the same, it is showing: undefined index error. The code is as below, pls help where I am wrong

<?php
if(isset($_POST["hdnsubmitted"]) 
{
for ($i=0;$i<6;$i++)
{

$curr_status=$_POST['curr_status'.$i]; echo $curr_status;
} 

$Status= "Status Updated";

}

 ?>


<form method="post" action="targetpage">
<table class="freeze-table">
     
        <thead>
           <tr >
            <th class="col-id-no fixed-header" >CURRENT STATUS</th>
            <th class="col-id-no fixed-header" >PENDING INPUTS</th>
             </tr>
          </thead>
       
    <?php
     $query="SELECT * FROM `status` WHERE 1";
            $sql=mysqli_query($conn,$query);
            $i=0;
            while ($row=mysqli_fetch_array($sql)){
            
                
            echo "<tr>
                  <td name='Curr_status'".$i."><div contenteditable>  ".$row['CURRENT_STATUS']."  </td>
                  <td name='Pending_Inputs'".$i."><div contenteditable>  ".$row['PENDING_INPUTS']."  </td>";
                    
             
   
          $i=$i+1;
          }
           
    ?>
  </tr>
    </table>
 <br>
    <button type="submit" name="btn_Update" class="btn_Update">Update</button>
    <p style="color:black;text-align: center"> <?php echo $Status; ?></p>
     </form>
uddipana
  • 188
  • 2
  • 19
  • Does this answer your question? ["Notice: Undefined variable", "Notice: Undefined index", "Warning: Undefined array key", and "Notice: Undefined offset" using PHP](https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-warning-undefined-arr) – Nico Haase Mar 29 '22 at 05:23
  • Please share which line causes the problem, along with yuor attempts to resolve the problem – Nico Haase Mar 29 '22 at 05:23
  • @NicoHaase. In php code section, when I am trying to echo the variable I am getting the undefined index error – uddipana Mar 29 '22 at 05:57
  • What does that mean? Which section do you mean? – Nico Haase Mar 29 '22 at 07:04

1 Answers1

0

You don't have any form. You have a table and table contents do not sent to php.

You must use a form with fields. Each field must have a name.

In below simplest example: method is post so your form content will be in $_POST. In targetpage.php page, try var_dump($_POST) to see the result after you submit the form.

You'll see $_POST is an array with these keys: email, name, submit.

form.php // php page that has the form    

<form action="targetpage.php" method="post">
  <div class="form-example">
    <label for="name">Enter your name: </label>
    <input type="text" name="name" id="name" required>
  </div>
  <div class="form-example">
    <label for="email">Enter your email: </label>
    <input type="email" name="email" id="email" required>
  </div>
  <div class="form-example">
    <input type="submit" value="Subscribe!">
  </div>
</form>
Ersin
  • 124
  • 3