13, October 2008

help with inserting checkbox form values. - webmaster forum

 
Webdigity webmaster forums
This forum shares its ad revenue with its members!
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: help with inserting checkbox form values.
« previous next »
Pages: [1] Print

Author Topic: help with inserting checkbox form values.  (Read 761 times)
Google dot what?
*
Posts: 2
16 credits
Members referred : 0


« on: Aug 16, 2007, 06:13:59 AM »

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)
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');

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 );

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>

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;
}

so, what's the deal here?
Global Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6349
38918 credits
Members referred : 374


It's time to use PHP5!


« Reply #1 on: Aug 18, 2007, 09:25:34 AM »

here is something wrong:

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;
}

must be

Code:
foreach ($_POST['PICTURES'] as $row)
{
      $pictures = mysql_real_escape_string($row);
      $persons = $_POST['persons'];
      mysql_query('INSERT INTO relations (relPics, person) VALUES ($row, $persons)') or die (mysql_error());
      echo $row." ".$persons;
}


Last blog : Upload images for usage in TinyMCE
Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=7010
Tags : Checkbox insert multiple items form Bookmark this thread : Digg Del.icio.us Dzone more....

Topic sponsors:
Get a permanent link here for $1.99!


Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP
Topic: help with inserting checkbox form values.
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
Oct 13, 2008, 08:39:47 AM





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!


Forum Statistics
Total Posts: 36.944
Total Topics: 7.560
Total Members: 4.153
Tutorials : 56
Resources : 143
Designs : 220
Latest Member: Chalky566

25 Guests, 4 Users online :

16 users online today:



Readers

Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2008 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.