Click here to Skip to main content
15,890,609 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

How can I insert multiple selected checkboxe(s) in a database and then retrieve it back later in the different table ? the code is below
Posted
Updated 9-Sep-10 1:24am
v4
Comments
shiana87 9-Sep-10 7:20am    
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<?php
include("dbconnect.php");
$sql=mysql_query("select * from my_tbl");
while($res=mysql_fetch_array($sql))
{
?>
<input type="textbox" name="checkbox[]" value="<?php echo $res['id']?>" />
<?php
foreach ($_POST[$res['id']] as $val)
{
echo "$val,";
}

{
$sql=mysql_query("insert into temp(temp_id,temp_name)values(".$ival.")");
}
if($sql)
{
echo "inserted";
}
else
{
echo "try again";
}
}


?>
<form name="frm" action="shiana.php" method="post"/>
<input type="submit" name="submit" value="submit" />

</body>
</html>
shiana87 9-Sep-10 7:21am    
whr is the mistake ,,,,,, :(

1 solution

For this, selected checkboxes must represnt some unique identifier/key. Store the unique keys of selected checkboxes. Retrieve the keys when needed to show the selection.
 
Share this answer
 
Comments
shiana87 9-Sep-10 7:19am    
Respected Sir I did the same but unable to get the results .

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900