Hello Hope every one will be good. I have a problem.
I have a form following form code.
<form name="form3" method="post" action="">
<?php while ($row_news1 = mysql_fetch_assoc($rs_news1)) { ?>
<input type="checkbox" name="check1[]" value="1" <?php if($row_news1['house']=='1') echo "checked=\"checked\""; ?>>
<input type="checkbox" name="check2[]" value="1" <?php if($row_news1['add_item']=='1') echo "checked=\"checked\""; ?>>
<input type="text" name="user_name[]" id="textfield" readonly style="width:50%;color:white;background-color:transparent" value="<?php echo $row_news1['FirstName'].' '.$row_news1['LastName']; ?>"><br>
<input type="hidden" name="user_id[]" value="<?php echo $row_news1['UserID']; ?>">
<?php } ?>
<input type="submit" value="Submit" name="update" class="but">
<input type="submit" value="Reset" name="reset" class="but">
</form>
I want that how much the user name record comes to an array. That much time the two check boxes will be Generated. So when i checked all the check boxes so the table update successfully. But when i want to checked some check boxes randomly.so their corresponding record will be update with Value 1 and all other unchecked check boxes Corresponding Record will be updated with the Value of 0.
Here is my Form Submission code.
if(isset($_POST['update'])&& $_POST['user_name']!=''){ // checking if Update button clicked
$user_id=$_POST['user_id']; // Getting all user_id
$user_name= $_POST['user_name']; //Getting user name text box
$check1=$_POST['check1'];// Getting all check boxes but in this case its only taking checked boxes.
$check2=$_POST['check2'];
for($i = 0; $i < count($user_name); $i++){ // iterating the code until we have user name.
if($check1[$i]=='1'){ // checked if first checkbox value is 1 so assign 1 to Variable a. other wise 0;
$a=1;
}
else {
$a=0;
}
if($check2[$i]=='1'){ // same as above i want
$b=1;
}
else {
$b=0;
}
// this is the query that i want to update the rocord
$query_u1 = "UPDATE Users
SET
house = '".$a."',
add_item = '".$b."'
WHERE UserID=".$user_id[$i];
mysql_query($query_u1) or die(mysql_error());
}
echo '<script> window.location = "adminmain.php";</script>';
}
The above code shows my Php and mysql query code.
Now i Want that i get all check boxes checked or not. just the other things. Means i have 10 Record for users. Every record have their UserId and name. With Every Record I have Two check Boxes as show in code.
I want when i checked 5 check boxes Randomly. so these five corresponding record will be updated with 1 value. and other five check boxes corresponding record will updated with 0 value.
I think you people will got it now.