Is it possible to generate dynamic array names for input checkbox forms ?
I'm using this code to generate a form of text fields and checkboxs
Code: Select all
<?php
require_once("includes/connection.php");
require_once("includes/functions.php");
include("includes/header.php");
?>
<?php
$query = "SELECT key_id, words FROM keywords";
$result = mysql_query($query);
confirm_query($result);
$options = "";
while($row = mysql_fetch_array($result)){
$options .= "{$row[1]}:<input type=\"checkbox\" value=".$row[0]." name=\"section[]\" />\n";
}
$number_of_uploads = 3;
?>
<body>
<div id="con">
<form name="upload_form" action="upload.php" method="post" enctype="multipart/form-data">
<?php
for($counter = 1;$counter<=$number_of_uploads;$counter++){
?>
<p>
<b>Image:</b>
<textarea name="title[]" cols="30" rows="1"></textarea>
</p>
<p>
<b>Sections:</b>
<?php echo $options ;?>
</p>
<?php
}
?>
<br/>
<p>
<input type="submit" name="submit" value="Add Photos" />
</p>
</form>
</div>
</body>
</html>
Code: Select all
while($row = mysql_fetch_array($result)){
$options .= "{$row[1]}:<input type=\"checkbox\" value=".$row[0]." name=\"section[]\" />\n";
}
Something like:
Code: Select all
name="section[].$row[0]\"
How can I then access this array with php from the $_POST array ?
I thought I might be able to access the array with something like:
But this doesn't work.
Code: Select all
<?php
echo "<pre>";
print_r($_POST['section'['.1.']]);
echo "</pre>";
?>