Reputation: 242
I have this code. i just want to delete the record that i want to delete but when i click the button delete it only delete the last data record added what should i do ? Thankyou in advance
if(isset($_POST['delete'])){
$id = $_POST['delete_rec_id'];
$query=mysqli_query($link,"Delete from hgrecord where PossibleCondition ='".$id."' ");
}
if(isset($_GET["poscon"])){
$kwery=mysqli_query($link,"select Distinct PossibleCondition from hgrecord where PatientId='".$session."' and Date='".$new_time."' order by PossibleCondition");
while($rr=mysqli_fetch_array($kwery)){
$PatientId=$rr["PatientId"];
$condition1=$rr["PossibleCondition"];
if(isset($_POST) && isset($_POST['sym1']) && in_array($condition1,$_POST['sym1']))
$strIsChecked='checked="checked"';
else
$strIsChecked=null;
echo '<br><td><input type="checkbox" '.$strIsChecked.' title ="'.$otherspec1.'" name="sym1[]" onclick="javascript: submit()" value ="'.$condition1.'"></td>';
echo '<td align="">'.$condition1.'</td>';
?>
<button type="submit" name="delete" aria-label="Left Align">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
<input type="hidden" name="delete_rec_id" value="<?php print $condition1;
?>"/>
<?php } } ?>
Upvotes: 2
Views: 52
Reputation: 106
Not sure what you are doing in your javascript function javascript: submit()
What I can suggest it, add the functionality in your javascript function to collect(comma separated values) all the checked checkboxes and assign it to the hidden field delete_rec_id
.
Upvotes: 0
Reputation: 2949
You have to add your form
tag around each set of button and hidden input:
<form action="#" method="post">
<button type="submit" name="delete" aria-label="Left Align">
<span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
</button>
<input type="hidden" name="delete_rec_id" value="<?php print $condition1;" />
</form>
Otherwise you'll have one form with multiple hidden inputs with name="delete_rec_id"
.
Upvotes: 2