Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Inserting checkbox values into database
Old 10-27-2008, 10:56 PM Inserting checkbox values into database
Junior Talker

Posts: 3
Trades: 0
Hi to all

I need help for this problem that i'm trying to solve for a while (i'm new in PHP).
I have a form with several checkboxes which values are pulled from a database.
I managed to display them in the form, assign an appropriate value to each, but cannot insert their values into other database.

Here's the code:




Quote:
<form id="form1" name="form1" method="post" action="">
<?php
$info_id=$_GET['info_id'];
$kv_dodatoci=mysql_query("SELECT * FROM `dodatoci`") or die('ERROR DISPLAYING: '.mysql_error());
while($kol=mysql_fetch_array($kv_dodatoci)){
$id_dodatoci=$kol['id_dodatoci'];
$mk=$kol['mk'];


echo '<input type="checkbox" name="id_dodatoci[]" id="id_dodatoci" value="'.$id_dodatoci.'" />';
echo '<label for="'.$id_dodatoci.'">'.$mk.'</label><br />';
}
?>
<input type="hidden" value="<?=$info_id?>" name="info_id" />
<input name="insert_info" type="submit" value="Insert Additional info" />
</form>
<?php
if(isset($_POST['insert_info']) && is_array($id_dodatoci)){
echo $id_dodatoci.'<br />';
echo $mk.'<br />';

// --- Guess here's the problem ----- //
foreach($_POST['id_dodatoci'] as $dodatok){
$dodatok_kv=mysql_query("INSERT INTO `dodatoci_hotel`(id_dodatoci,info_id) VALUES ('$dodatok','$info_id')") or die('ERROR INSERTING: '.mysql_error());
}

}


?>










my problem is to loop through all checkboxes, and for each checked, populate a separate record in a database.
actually i don't know how to recognize the which box is checked, and put the appropriate value in db.


I hope someone can help me solve this or give me some guideline.

Thanks in advance.
dedurus is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-28-2008, 04:36 AM Re: Inserting checkbox values into database
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Here's a clue
Only a checked check box will return a key\value pair.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 10-28-2008, 04:59 AM Re: Inserting checkbox values into database
mtishetsky's Avatar
King Spam Talker

Posts: 1,226
Name: Mike
Location: Mataro, Spain
Trades: 0
PHP Code:
<? foreach ($ids as $id): ?>
<input type="hidden"   name="boxes[<?= $id ?>]" value="0" />
<input type="checkbox" name="boxes[<?= $id ?>]" value="1" />
<? endforeach ?>
__________________

Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE
-
Please login or register to view this content. Registration is FREE

And don't forget to give me talkupation!
mtishetsky is offline
Reply With Quote
View Public Profile Visit mtishetsky's homepage!
 
Reply     « Reply to Inserting checkbox values into database
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.12209 seconds with 12 queries