I need to have 30 checkboxes on one page in a form - after the form is submitted with a separate script I want a loop to run through the values i.e.
1- checked
2- unchecked
3- unchecked
4 - checked
And store this in a database as 1,4 i.e. only store checked ones.
This is what I have so far but is not doing the job - only getting last checked.
<form action="script.php" method="post" enctype="multipart/form-data">
<table>
<tr style="vertical-align: top;">
<td width="400px">
Upload product file:<br />
<input type="file" name="upload" value="FILENAME" /><br />
Product description:<br />
<textarea rows="7" cols="41" name="desc"></textarea><br />
</td>
<td>
Product Price:<br />
<input type="text" name="price" maxlength="11" /><br />
Product reference:<br />
<input type="text" name="ref" maxlength="7" /><br />
Other product information:<br />
<input type="text" name="other" maxlength="100" /><br />
</td>
<td>
Product technology:<br />
<input type="checkbox" name="technology_checkboxes1" value="Laptop sleeve">Laptop sleeve<br>
<input type="checkbox" name="technology_checkboxes2" value="Digital media pocket">Digital media pocket<br>
<input type="checkbox" name="technology_checkboxes3" value="Audio pocket">Audio pocket<br>
<input type="checkbox" name="technology_checkboxes4" value="Cell Pocket">Cell Pocket<br>
<input type="checkbox" name="technology_checkboxes5" value="Hydration Ready">Hydration Ready<br>
</td>
<td>
Product technology continued:<br />
</td>
</tr>
</table>
<input type="submit" value="Upload" /><br />
</form>
$tech = "0";
for($i =0; $i<=30; $i++)
{
if(isset($_POST['technology_checkboxes'.$i]))
{
$tech = ",".$i;
}
}
// Bail out if the file isn’t really an upload.
if (!is_uploaded_file($_FILES['upload']['tmp_name']))
{
exit('There was no file uploaded!');
}
$uploadfile = $_FILES['upload']['tmp_name'];
$uploadname = $_FILES['upload']['name'];
$uploadtype = $_FILES['upload']['type'];
$price = $_POST['price'];
$desc = $_POST['desc'];
//$tech = $_POST['tech'];
$ref = $_POST['ref'];
$other = $_POST['other'];
// Open file for binary reading ('rb')
$tempfile = fopen($uploadfile, 'rb');
// Read the entire file into memory using PHP's
// filesize function to get the file size.
$filedata = fread($tempfile, filesize($uploadfile));
// Prepare for database insert by adding backslashes
// before special characters.
$filedata = addslashes($filedata);
$connector->query("INSERT INTO filestore SET filename = '$uploadname', mimetype = '$uploadtype', description = '$desc', filedata = '$filedata', price = '$price', technology = '$tech', reference = '$ref', other_information = '$other'");
header ("Location: add_product.php");
exit();
}
Cheers anyone