User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 403,494 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,285 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 4707 | Replies: 1
Reply
Join Date: Feb 2006
Posts: 1
Reputation: bearbrick is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
bearbrick bearbrick is offline Offline
Newbie Poster

Help with Dynamic Checkbox

  #1  
Feb 2nd, 2006
hye all, im here just want to ask for a very basic problem about checkbox. i do search but there is nothing related to my problem.

my problem is :

1 - i have a dynamic table with checkbox on each row of my table.

2 - each row has different value since it carry out from my database.

3 - i want to multiple add from the selected checkbox into the other table.

4 - thing is fine but then, there is no value carry to the database. ( i noticed that i don carry any value into it, i dont know how to do that ).

here is the sample of my code :

//<?php
while($rows=mysql_fetch_array($result)){
?>
<tr bgcolor="#B9DAFC">
<td align="center" class="text">
<? echo $rows['subject_id']; ?></td>
<td class="text">
<? echo $rows['subject_name']; ?> </td>
<td align="center" class="text">
<input name="checkbox[]" type="checkbox" id="checkbox[]" value="<? echo $rows['id']; ?>">
</td>
</tr>
<?php
}
?>


<tr align="right">
<td colspan="3" bgcolor="#FFFFFF">
<input name="add" type="submit" id="add" value="Add!">
</td>
</tr>
<?
if($add){
foreach($_POST['checkbox'] as $add_id)
{
//for($i=0;$i<$count;$i++){
$add_id = $checkbox[$i];
$sql = "INSERT INTO $tbl_name2 (subject_id, subject_name) VALUES ('$add_id', '$add_id')";
$result = mysql_query($sql);
}

// if successful redirect to user.php
if($result){
echo "<meta http-equiv=\"refresh\" content=\"0;URL=user.php\">";
}
}
mysql_close();
?>

thank you in advance.
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Sep 2005
Location: Netherlands
Posts: 9
Reputation: olaf is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
olaf olaf is offline Offline
Newbie Poster

Re: Help with Dynamic Checkbox

  #2  
Feb 7th, 2006
Hello, first place the the insert statemen at the top of your script. use an echo in front of the insert statement to debug if the values are filled.

Olaf
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 12:22 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC