elkidogz
Thu 16 August 2007, 06:13 am GMT +0300
i have a form that grabs data and displays it as a checkbox list. it pulls data from another table and displays this list as radio buttons.
I want to be able to select one radio button and multiple checkboxes, then have these values inserted into a third table.
My form is generated correctly (as far as i can tell) I am having trouble with how in the heck get the multiple checkboxes which are selected to insert there values into the table.
Form is as follows - this generates the checkboxes (a thumbnailed picture with a check box below and a title)
the radio is here:
the form is wrote out here:
here's the handle of it.
so, what's the deal here?
I want to be able to select one radio button and multiple checkboxes, then have these values inserted into a third table.
My form is generated correctly (as far as i can tell) I am having trouble with how in the heck get the multiple checkboxes which are selected to insert there values into the table.
Form is as follows - this generates the checkboxes (a thumbnailed picture with a check box below and a title)
Code:
$result = mysql_query("SELECT * FROM pictures");
$output="<tr>";
while($row = mysql_fetch_array($result))
{
$counter = $counter + 1;
$output .="<!--START ROW FOR checkbox " .$row['fileName']." --> ";
$output .=" <td width=10 id=left10 align=left ><!--".$counter."--><br></td>";
$output .=" <td width=120 id=middle align=center valign=top >";
$output .=" <a href=".$fileURL."".$row['fileName']." ><img src=".$fileURL."THUMBS/".$row['fileName']." ></a><br>";
$output .=" <input type=checkbox name=PICTURES[] value=".$row['fileName']." />".$row['picTitle']." ";
$output .=" </td>";
$output .=" <td width=10 id=right10 ><br></td>";
$output .="<!-- END ROW FOR checkbox " .$row['fileName']." -->";
if ( $counter % 4 == 0 )
{
$output .= "</tr><tr>";
}
}
$output .="</tr>";
// open the file
$fhandle = fopen( "FormParts/pictureCheckBoxes.php", "w" );
// write the contents of the $output variable to the file
fwrite( $fhandle, $output );
// close the file
fclose( $fhandle );
include('FormParts/pictureCheckBoxes.php');
$output="<tr>";
while($row = mysql_fetch_array($result))
{
$counter = $counter + 1;
$output .="<!--START ROW FOR checkbox " .$row['fileName']." --> ";
$output .=" <td width=10 id=left10 align=left ><!--".$counter."--><br></td>";
$output .=" <td width=120 id=middle align=center valign=top >";
$output .=" <a href=".$fileURL."".$row['fileName']." ><img src=".$fileURL."THUMBS/".$row['fileName']." ></a><br>";
$output .=" <input type=checkbox name=PICTURES[] value=".$row['fileName']." />".$row['picTitle']." ";
$output .=" </td>";
$output .=" <td width=10 id=right10 ><br></td>";
$output .="<!-- END ROW FOR checkbox " .$row['fileName']." -->";
if ( $counter % 4 == 0 )
{
$output .= "</tr><tr>";
}
}
$output .="</tr>";
// open the file
$fhandle = fopen( "FormParts/pictureCheckBoxes.php", "w" );
// write the contents of the $output variable to the file
fwrite( $fhandle, $output );
// close the file
fclose( $fhandle );
include('FormParts/pictureCheckBoxes.php');
the radio is here:
Code:
$result = mysql_query("SELECT * FROM persons");
$output="<tr>";
while($row = mysql_fetch_array($result))
{
$counter = $counter + 1;
$output .="<!-- START ROW FOR Radio " .$row['name']."--> ";
$output .=" <td width=10 id=left10 align=left valign=top >".$counter.". ";
$output .=" </td>";
$output .=" <td width=120 id=middle align=left valign=top >";
$output .=" <input type=radio name=PERSONS value=".$row['name']." >".$row['name'];
$output .=" </td>";
$output .=" <td width=10 id=right10 valign=top ></td>";
$output .="<!-- END ROW FOR Radio " .$row['Name']."--> ";
if ( $counter % 1 == 0 )
{
$output .= "</tr><tr>";
}
}
$output .="</tr>";
// open the file
$fhandle = fopen( "FormParts/personsBullets.php", "w" );
// write the contents of the $output variable to the file
fwrite( $fhandle, $output );
$output="<tr>";
while($row = mysql_fetch_array($result))
{
$counter = $counter + 1;
$output .="<!-- START ROW FOR Radio " .$row['name']."--> ";
$output .=" <td width=10 id=left10 align=left valign=top >".$counter.". ";
$output .=" </td>";
$output .=" <td width=120 id=middle align=left valign=top >";
$output .=" <input type=radio name=PERSONS value=".$row['name']." >".$row['name'];
$output .=" </td>";
$output .=" <td width=10 id=right10 valign=top ></td>";
$output .="<!-- END ROW FOR Radio " .$row['Name']."--> ";
if ( $counter % 1 == 0 )
{
$output .= "</tr><tr>";
}
}
$output .="</tr>";
// open the file
$fhandle = fopen( "FormParts/personsBullets.php", "w" );
// write the contents of the $output variable to the file
fwrite( $fhandle, $output );
the form is wrote out here:
Code:
<form id="makerelation" action="makerelation.php" method="POST">
<fieldset>
<legend>Relate pictures and person</legend>
<table id="makerelations" border="0" colspan="0" cellpadding="0" cellspacing="0" align="left">
<tr> <!-- | 140 |20 | 140 | -->
<td align="left">
Choose a person
</td>
<td width="5"><br>
</td>
<td align="left">
Pick the Pictures that include the person you chose.
</td>
</tr>
<td align="left" valign="top">
<table id="persons" width="140" border="0" colspan="0" cellpadding="0" cellspacing="0" align="left">
<tbody valign="top">
<?php include('makerb4allpeople.php'); ?>
</tbody>
</table> <!-- persons -->
</td>
<td width="5"><br>
</td>
<td align="left">
<table id="pictures" border="1" colspan="0" cellpadding="0" cellspacing="0" align="left">
<?php include('makecb4allpictures.php'); ?>
</table> <!-- pictures -->
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="submit" value="submit" name="Submit" />
<input type="reset" value="reset" name="Reset" />
</td>
</tr>
</table> <!-- makerelations -->
</fieldset>
</form>
<fieldset>
<legend>Relate pictures and person</legend>
<table id="makerelations" border="0" colspan="0" cellpadding="0" cellspacing="0" align="left">
<tr> <!-- | 140 |20 | 140 | -->
<td align="left">
Choose a person
</td>
<td width="5"><br>
</td>
<td align="left">
Pick the Pictures that include the person you chose.
</td>
</tr>
<td align="left" valign="top">
<table id="persons" width="140" border="0" colspan="0" cellpadding="0" cellspacing="0" align="left">
<tbody valign="top">
<?php include('makerb4allpeople.php'); ?>
</tbody>
</table> <!-- persons -->
</td>
<td width="5"><br>
</td>
<td align="left">
<table id="pictures" border="1" colspan="0" cellpadding="0" cellspacing="0" align="left">
<?php include('makecb4allpictures.php'); ?>
</table> <!-- pictures -->
</td>
</tr>
<tr>
<td colspan="3" align="center">
<input type="submit" value="submit" name="Submit" />
<input type="reset" value="reset" name="Reset" />
</td>
</tr>
</table> <!-- makerelations -->
</fieldset>
</form>
here's the handle of it.
Code:
foreach ($_POST['PICTURES'][] as $row=>$PICTURES)
{
$pictures = mysql_real_escape_string($PICTURES);
$persons = $_POST['persons'];
mysql_query('INSERT INTO relations (relPics, person) VALUES ($pictures, $persons)') or die (mysql_error());
echo $pictures." ".$persons;
}
{
$pictures = mysql_real_escape_string($PICTURES);
$persons = $_POST['persons'];
mysql_query('INSERT INTO relations (relPics, person) VALUES ($pictures, $persons)') or die (mysql_error());
echo $pictures." ".$persons;
}
so, what's the deal here?