I have a form that takes data from the db and displays it onto a table using a foreach loop. After reviewing the data, I want to insert that data into another table that is already in the DB via a button click. I have tried multiple ways, but can't seem to get it to work. Any help would be great. Thanks!
my index.php page
<div class='container-fluid'>
<div class='row'>
<div class='col-12'>
<div class='table table-responsive'>
<table class='table table-striped table-bordered datatable active' id='grantTable'>
<thead>
<tr>
<th>FP ID</th>
<th>Short Title</th>
<th>PI</th>
<th>Department</th>
<th>Division</th>
<th>Sponsor Name</th>
<th>Project Start</th>
<th>Project End</th>
<th>Funding Type</th>
<th>Yes/No</th>
<th>Proper Type If No</th>
<th>Comment</th>
</tr>
</thead>
<tbody>
<?php
//Foreach loop iterates through each column of $getallrows function
foreach($allRows as $rowID => $rowInfo){ ?>
<tr>
<td><?php echo $rowInfo['fpID'];?></td>
<td><?php echo $rowInfo['shortTitle'];?></td>
<td><?php echo $rowInfo['PI'];?></td>
<td><?php echo $rowInfo['Department'];?></td>
<td><?php echo $rowInfo['Division'];?></td>
<td><?php echo $rowInfo['sponsorName'];?></td>
<td><?php echo $rowInfo['Date_Project_Start']->format('Y-m-d');?></td>
<td><?php echo $rowInfo['Date_Project_End']->format('Y-m-d');?></td>
<td><?php echo $rowInfo['fundingType'];?></td>
<!-- //Create dynamic id -->
<?php $rdDrop = "ddgrantType_".$rowInfo['fpID'];?>
<form action="process.php" method="POST">
<td>Yes<input type="radio" name="rdGrant[<?php echo $rowInfo['fpID'];?>]" value="Yes" id="rdYes" onclick="disable('<?php echo $rdDrop;?>')" checked/><br />
No<input type="radio" name="rdGrant[<?php echo $rowInfo['fpID'];?>]" value="No" id="rdNo" onclick="enable('<?php echo $rdDrop;?>')"/></td>
<input type="hidden" name="id" value="<?php echo $fpID; ?>"/>
<td>
<div class="dropdown">
<button class="btn btn-secondary btn-sm dropdown-toggle" type="button" name="ddgrantGroup" id="<?php echo $rdDrop;?>" data-toggle="dropdown" disabled>Select Proper Funding Type
<span class="caret"></span>
</button>
<ul class="dropdown-menu" aria-labelledby="ddgrantType">
<li><a data-value="Corporate Sponsor">Corporate Sponsor</a></li>
<li><a data-value="Federal">Federal</a></li>
<li><a data-value="Foundation Selected">Foundation Selected</a></li>
<li><a data-value="Internally Funded">Internally Funded</a></li>
<li><a data-value="State/Local">State/Local</a></li>
</ul>
</div>
</td>
<td>
<div class="comment">
<textarea class="form-control" aria-label="With textarea" id="grantComment" placeholder="Comments"></textarea>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
<div class="flex-container" id="saveBtn">
<div class="dSave"><button type="submit" class="btn btn-success" name="submit" id="Save">Save</button></div>
<div><button type="submit" class="btn btn-success" name="Complete" id="Complete">Complete and Save</button></div>
</div>
</form>
</div>
</div>
</div>
</div>
My process.php page
if(isset($_POST['submit'])) {
$count = count($_POST['fpID']);
for($i=0; $i < count; $i++) {
$mssql = "INSERT into some_table (FP_id, Short_Title, PI, Department, Division, Sponsor, Date_Project_Start, Date_Project_End, Funding_Type, Yes_No, Proper_Type_If_No, Comment, Complete_Flag)
VALUES ('"
$mssql .= $_POST['Funding Proposal ID'][$i] . "','";
$mssql .= $_POST['Short Title'][$i] . "','";
$mssql .= $_POST['PI'][$i] . "','";
$mssql .= $_POST['Department'][$i] . "','";
$mssql .= $_POST['Division'][$i] . "','";
$mssql .= $_POST['Sponsor Name'][$i] . "','";
$mssql .= $_POST['Date_Project_Start'][$i] . "','";
$mssql .= $_POST['Date_Project_End'][$i] . "','";
$mssql .= $_POST['Funding Type'][$i] . "','";
$mssql .= $_POST['Yes_No'][$i] . "','";
$mssql .= $_POST['Proper_Type_If_No'][$i] . "','";
$mssql .= $_POST['Comment][$i] . "','";
$mssql .= 'No' "')";
}
header("Location: index.php");
}
?>
Aucun commentaire:
Enregistrer un commentaire