Saturday, 31 August 2013

Changing status with updating record

Changing status with updating record

Getting drop-down value to update status and comments.
<?php
require_once("db.php");
if(isset($_POST['submit'],$_POST['chkParamId'])){
$count=0;
if(!empty($_POST['chkParamId'])){
foreach($_POST['chkParamId'] as $ChkbxId){
$comments=$_POST['comments'][$count];
$dropval=$_POST['statusDrop'][$count];
$count++;
mysql_query("update comments_tbl set is_enabled='$dropval' ,
comments='$comments' where comments_id='$ChkbxId'");
}
}
};
?>
HTML: using Checkbox(value=DB IDs) and a Dropdown(value=enable or disable)
Problem: updating only 1st record and not others.
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post"><tbody><tr>
<td><input type="checkbox" name="chkParamId[]" id="chkParamId[]"
value="<?php echo $row['comments_id'];?>" /><p><select
name="statusDrop[]"><option <?php
if($row['is_enabled']=='1'){?>selected="selected"<?php };?>
value="1">Enable</option>
<option <?php
if($row['is_enabled']=='0'){?>selected="selected"<?php };?>
value="0">Disable</option>
</select>
</form>

No comments:

Post a Comment