To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
PHPBuilder.com  
 

 

Go Back   PHPBuilder.com > Tools > Dreamweaver

Dreamweaver In need of help with Dreamweaver?

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-30-2003, 12:48 AM   #1
kmiec
Junior Member
 
Join Date: Jun 2003
Posts: 3
inserting checkbox ID's into a lookup table?

I am creating a form that allows the user to Submit a property with it's address and ammenities. I have the ammenities listed in a form table with check boxes. I want the user to be able to check all the different ammenities that aply to the house. I'll show a an example of the table.

tr>
<td width="4%"><input type="checkbox" name="Furnished" value="1"></td>
<td width="12%">Furnished</td>
<td width="4%"><input type="checkbox" name="Unfurnished" value="2"></td>
<td width="15%">Unfurnished</td>
<td width="4%"><input type="checkbox" name="Capreted" value="3"></td>
<td width="15%">Capreted</td>
<td width="4%"><input type="checkbox" name="HFloors" value="4"></td>
<td width="17%">Hardwood Floors</td>
<td width="2%"><input type="checkbox" name="Stove" value="5"></td>
<td width="23%">Stove</td>
</tr>

What I want is to have the value of the checked boxes (the Amenities ID) insterted in a lookup table (AID / PID) with the Property ID of the users Property.

I'm sure I'll have to do some manual coding but I've been trying and can't get it to work. Does anyone have any Ideas how to get this done in Dreamweaver.

Thanks
kmiec is offline   Reply With Quote
Old 06-30-2003, 08:57 AM   #2
ahundiak
Bright Member
 
ahundiak's Avatar
 
Join Date: Aug 2002
Posts: 1,608
Actually, you can (and should) have a value for check box elements. It's the value that ends up being submitted when the box is checked.
ahundiak is offline   Reply With Quote
Old 06-30-2003, 12:39 PM   #3
kmiec
Junior Member
 
Join Date: Jun 2003
Posts: 3
I'm sure that you can have a value for the checkbox. And it is the value of the Amen's ID that I would like to insert to the Lookup Table. Can anyone actually explain what I can do to have that value inserted to the lookup table with the Property ID? ie.

PID / AID Where Property ID = 3
------------
3 1
3 3
3 5

Thanks
kmiec is offline   Reply With Quote
Old 07-01-2003, 04:52 AM   #4
goa103
Senior Member
 
goa103's Avatar
 
Join Date: Aug 2002
Posts: 199
Quote:
Originally posted by kmiec
I'm sure that you can have a value for the checkbox. And it is the value of the Amen's ID that I would like to insert to the Lookup Table. Can anyone actually explain what I can do to have that value inserted to the lookup table with the Property ID? ie.

PID / AID Where Property ID = 3
------------
3 1
3 3
3 5

Thanks
You don't need a value for the checkbox. Its value is 1 or 0 (TRUE or FALSE).
Update by goa103 : I can't believe i wrote that . Set the VALUE of the checkbox to an id (user id for a user selection...), once submitted a PHP variable is created for all checked checkboxes : $_POST ['my_checkbox'] returns the VALUE of the checkbox.

Use a hidden field to store your PID or AID :

<input type="hidden" name="pid" value="<? $pid ?>">
...

JM
__________________
"Most of the people are so lazy that they don't even search for an answer to their question on Google.
So do I
Google... Do you want to know more ?"

Last edited by goa103; 07-01-2003 at 11:43 PM.
goa103 is offline   Reply With Quote
Old 07-01-2003, 09:04 AM   #5
ahundiak
Bright Member
 
ahundiak's Avatar
 
Join Date: Aug 2002
Posts: 1,608
goa103,
I don't think your post is entirely accurate. An unchecked checkbox does not post at all. It's simply skipped and it does not get a value of 0. A posted checkbox will have either a value of 'on' or whatever the value attribute has.
PHP Code:
<form method="post" action="test.php">
<input type="checkbox" name="box">Check Me</input><br />
<input type="checkbox" name="boxes[]" value="24">Check Me</input><br />
<input type="checkbox" name="boxes[]" value="42">Check Me</input><br />
<input type="submit"   name="submit"  value="Submit">
</form>
<?php
  error_reporting
(E_ALL);
  if (isset(
$_POST['submit']))
  {
    if (isset(
$_POST['box']))
    {
      echo
'BOX ' . $_POST['box'] . '<br />';
    }
    else echo
'BOX NOT SET <br />';

    if (isset(
$_POST['boxes']))
    {
      
$boxes = $_POST['boxes'];
      foreach (
$boxes as $box)
      {
        echo
'BOXES ' . $box . '<br />';
      }
    }
    else echo
'BOXES NOT SET <br />';
  }
?>
Try submiting with and without the 'box' element being checked. See the difference?

Where it becomes more challenging is when you have an array of check boxes. Unchecked boxes don't even post so the only way of knowing which boxes were checked is being giving them a unique value.
ahundiak is offline   Reply With Quote
Old 07-01-2003, 11:09 PM   #6
kmiec
Junior Member
 
Join Date: Jun 2003
Posts: 3
ahundiak

Your post actually makes a lot of sense and I see the difference between the box checked and not checked. Now, what would the code look like to insert the value into a lookup table if the values of the checkboxes were to be inserted into the AID and the value of a hidden field entered into the PID?

Thanks
kmiec is offline   Reply With Quote
Old 07-01-2003, 11:45 PM   #7
goa103
Senior Member
 
goa103's Avatar
 
Join Date: Aug 2002
Posts: 199
Quote:
Originally posted by ahundiak
goa103,
I don't think your post is entirely accurate. An unchecked checkbox does not post at all. It's simply skipped and it does not get a value of 0. A posted checkbox will have either a value of 'on' or whatever the value attribute has.
Well actually I think my answer doesn't make sense at all . I can't believe I wrote that so I updated my post. Probably because I'm jumping between PHP and a lot of other technologies.

So the checkbox VALUE matters. Read my update for more info.

Sorry again for the weird reply, I think I lost it
JM
__________________
"Most of the people are so lazy that they don't even search for an answer to their question on Google.
So do I
Google... Do you want to know more ?"
goa103 is offline   Reply With Quote
Old 07-01-2003, 11:58 PM   #8
ahundiak
Bright Member
 
ahundiak's Avatar
 
Join Date: Aug 2002
Posts: 1,608
PHP Code:
function db_query($sql)
{
  
$mysql_query($sql);
  if (
mysql_errno() == 0) return;
  die(
htmlspecialchars(mysql_error()) . '<br />' . htmlspecialchars($sql));
}

$pid = $_POST['pid'];
$sql = "DELETE FROM pid_aid WHERE pid=$pid";
db_query($sql);

if (isset(
$_POST['aids'])) $aids = $_POST['aids'];
else                       
$aids = array();

foreach(
$aids as $aid)
{
  
$sql = "INSERT INTO pid_aid VALUES($pid,$aid)";
  
db_query($sql);
}
That should get your started.
Make sure the user actually pressed the submit button. And create a unique index on just to make sure you never get duplicates.
ahundiak is offline   Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


All times are GMT -4. The time now is 03:40 PM.






Acceptable Use Policy

internet.comMediabistrojusttechjobs.comGraphics.com

WebMediaBrands Corporate Info


Advertise | Newsletters | Feedback | Submit News

Legal Notices | Licensing | Permissions | Privacy Policy


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.