I have search this forum and found all sorts of info that helped me.
I am stuck on one thing right now and that is my form being posted to a php processing page.
On the form is a number of checkboxes for saving settings.
The list of checkboxes grow and shrink depending on the number of records pulled in.
Now my issue is when I click save, the checkboxes jump up to the top where there was no checks in the boxes. I found out this is due to the fact that unless a checkbox is checked it doesn't exist and therefore never gets submitted ot my processing page which reads the array and inputs the data in mysql.
Here is an example to help better understand:
In this example I have 7 items which have their ID numbers, I got two check boxes per item (total of 14 checkboxes) one named all_prints, other named act_download. Here is a submission with all them unchecked:
=all_prints for ID=7
=act_download' for ID=7
=all_prints for ID=8
=act_download' for ID=8
=all_prints for ID=9
=act_download' for ID=9
=all_prints for ID=10
=act_download' for ID=10
=all_prints for ID=11
=act_download' for ID=11
=all_prints for ID=12
=act_download' for ID=12
=all_prints for ID=13
=act_download' for ID=13
Now with them all checked:
1=all_prints for ID=7
1=act_download' for ID=7
1=all_prints for ID=8
1=act_download' for ID=8
1=all_prints for ID=9
1=act_download' for ID=9
1=all_prints for ID=10
1=act_download' for ID=10
1=all_prints for ID=11
1=act_download' for ID=11
1=all_prints for ID=12
1=act_download' for ID=12
1=all_prints for ID=13
1=act_download' for ID=13
Now with say ID 13 all check, rest uncheck (here is when the problem starts):
1=all_prints for ID=7
1=act_download' for ID=7
=all_prints for ID=8
=act_download' for ID=8
=all_prints for ID=9
=act_download' for ID=9
=all_prints for ID=10
=act_download' for ID=10
=all_prints for ID=11
=act_download' for ID=11
=all_prints for ID=12
=act_download' for ID=12
=all_prints for ID=13
=act_download' for ID=13
Notice the checks jump up to ID 7. I think this is because when the array is created there is only one check in the array, and my processing page goes through that array and that is all there is one key.
Is there a better way to make this?
Form code:
<input type="checkbox" name="act_download[]" value="1" <? if($pg->act_download == 1){ echo "checked"; }?>>
<font face="arial" color="#ffffff" style="font-size: 11;"><br>
<b>Allow ALL Prints</b><br>
<input type="checkbox" name="all_prints[]" value="1" <?php if($pg->all_prints){ echo "checked"; } ?>><br>
Processing code:
$result_pg = mysql_query("SELECT id FROM photo_package", $db);
$i = 0;
while($rs3 = mysql_fetch_object($result_pg)){
if($_POST[$rs3->id . "_main_id"] == "1"){
$id = $rs3->id;
echo $_POST['all_prints'][$i] . "=all_prints for ID=" . $id . "<br>";
echo $_POST['act_download'][$i] . "=act_download' for ID=" . $id . "<br>";
$sql = "UPDATE photo_package SET title='" . $_POST['title'][$i] . "',description='" . $_POST['description'][$i] . "',keywords='" . $_POST['keywords'][$i] . "',photographer='" . $_POST['photographer'][$i] . "',all_prints='" . $_POST['all_prints'][$i] . "',act_download='" . $_POST['act_download'][$i] . "' WHERE id = '$id'";
$result = mysql_query($sql);
$photo_result = mysql_query("SELECT * FROM uploaded_images where reference_id = '$id' order by 'id'", $db);
$photo_rows = mysql_num_rows($photo_result);
$photo = mysql_fetch_object($photo_result);
$sql = "UPDATE uploaded_images SET price='" . $_POST['price'][$i] . "',quality='" . $_POST['quality'][$i] . "' WHERE id = '$photo->id'";
$result = mysql_query($sql);
$i++;
}
}
Ignore the two echo lines in there, that was used to output the data on what was being carried over above.