I am getting the error: Undefined index: data when running the code below
Here are the key parts of the code including sections that work fine:
I create a form to select dates - this all works fine
<div class="dates">
<form method="POST" action="">
<label for="StartDate">Start Date:</span></label>
<input type="datetime-local" id="StartDate" name="StartDate" value="<?php
if(isset($_POST['StartDate'])){echo $_POST['StartDate'];}?>"/>
<label for="EndDate">End Date:</span></label>
<input type="datetime-local" id="EndDate" name="EndDate" value="<?php if(isset($_POST['EndDate']))
{echo $_POST['EndDate'];}?>"/>
<input type="submit">
</form>
</Body>
</HTML>
</div>
I then run an sql query and add a checkbox to each line of data. I use lead_id as the value. This all displays fine and the value is being assigned correctly:
$result = mysqli_query($link,$query);
while ($row = mysqli_fetch_assoc($result))
{
?>
<form method="POST">
<?php
echo '<tr><td>'.$row['lead_id'].'</td>';
echo '<td>'.$row['status'].'</td>';
echo '<td>'.$row['campaign_id'].'</td>';
echo '<td>'.$row['call_date'].'</td>';
echo '<td>'.$row['user'].'</td>';
echo '<td>'.$row['status_name'].'</td>';
?>
<td><input type="checkbox" value='<?php echo $row['lead_id']?>' name="data[]"/></td></tr>";
</form>
<?php
}
I then have a submit button which is used to trigger an email - that all works aprt from it needs to contain the lead ids from the checked boxes and it doesnt due to this error
?>
<div>
<form method="post">
<input type="submit" name="Button1"
value="Send Email"/>
</form>
</head>
</div>
The error I get is Undefined Index: data
I am using the below code to attempt to output the data on screen as well as var_dump. All come out NULL as clearly for some reason it is not picking up the POST.
if(isset($_POST['data']) && !empty($_POST['data']))
foreach($_POST['data'] as $name) echo $name;
Id be grateful if anyone can see my error.