/    Sign up×
Community /Pin to ProfileBookmark

How to update multiple rows by checkbox in php?

Hi All I’m new to this. I am currently working on a project and stuck at this. In my Project I want to update multiple rows of fields by selecting checkbox.
But some issues occurred. The Code is

[B][U]index.php?option=features_sb[/U][/B]

[code=php]
<?php
include_once(“phpfiles/connection.php”);
$sql=”select * from admn_servce”;
$result=mysql_query($sql);
?>
<html>
<head>
<script language=”javascript” type=”text/javascript”>
// Redirect user to update details page
function vpb_update_data_redirection()
{
document.vpb_form_name.action = “erpfiles/update_srvce.php”;
document.vpb_form_name.submit();
}

// Redirect to delete detail page and perform user detail deletion
function vpb_delete_data_redirection()
{
if(confirm(“Do you really mean to delete the details?”))
{
document.vpb_form_name.action = “erpfiles/delete_srvce.php”;
document.vpb_form_name.submit();
}
}
</script>
</head>
<body>
<form action=”” method=”post” name=”vpb_form_name” enctype=”multipart/form-data”>
<div class=”edit-buttons”><div class=”edit-heading”>Click On The Help Button To Know More Details</div> <input type=”submit” name=”srvce_delete” id=”srvce_delete” class=”delete-sub” value=”Delete” onClick=”vpb_delete_data_redirection();”> <input type=”submit” class=”edit-sub” value=”Edit” name=”srvce_edit” onClick=”vpb_update_data_redirection();”> <input type=”submit” class=”save” value=”Save” name=”srvce_save”>
</div>
<?php

if(mysql_num_rows($result)>0)
{

while($row=mysql_fetch_array($result))
{

?>

<div class=”service-add-form”>
<div class=”service-add-row”>
<div class=”service-image”><img src=”uploads/<?php echo $row[‘admn_srvce_img’]; ?>”>
</div>
<div class=”image-upload”><input type=”file” name=”slider1″ >
</div>
<div class=”service-title”>Title</div>
<input type=”text” class=”servc-title-textbox” name=”srvce_title” value=”<?php echo $row[‘admn_srvce_title’]; ?>”>
<textarea class=”srvce-add-cntnt” rows=”4″ cols=”40″ name=”srvce_desc”><?php echo $row[‘admn_srvce_desc’]; ?></textarea>
<div class=”service-choose”><input name=”users[]” type=”checkbox” id=”users” value=”<?php echo $row[‘admn_srvce_id’]; ?>”></div>
</div>
</div>

<?php

}
}
?>

</form>
</body></html>[/code]

[B][U]update_srvce.php[/U][/B]

[code=php]
<?php
include_once(“../phpfiles/connection.php”);

$selected_users_id = count($_POST[“users”]);
for($i=0; $i<$selected_users_id; $i++)
{
$srvce_title=$_POST[‘srvce_title’];
$srvce_desc=$_POST[‘srvce_desc’];
$a=(strip_tags($_POST[“users”][$i]));
$sql1=”update admn_servce set admn_srvce_title=’$srvce_title’, admn_srvce_desc=’$srvce_desc’ where admn_srvce_id =’$a'”;
$result1=mysql_query($sql1);
}
echo “<script>window.location=’../index.php?option=features_sb'</script>”;
?>
[/code]

Database Table has 4 field
admn_srvce_id,srvce_title,srvce_desc,srvce_image

Can anyone help me with this code thanks….

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@ginerjmOct 31.2015 — Maybe you want to tell us what the issues are???

One problem is that you have a single form but have multiple rows of data items with the same name. You did manage to create an array of checkbox inputs but you used the same name value for all of the other fields. That won't work. OTOH, you can't just use arrays for all the fields because there is no correlation between the checkbox you click on and the data item you provide. The way to do this is to assign a unique id to the checkbox (which I think you are doing) but also assign that same id to each of the data field names so that you can make the connection between the checkbox selected and the data that belongs to it.
×

Success!

Help @syamsree21 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...