开发者

insert checkbox values into database within a separate column of the query separated by commas

I need help for this problem that I've been trying to solve for a while (I'm new in PHP). I have a form with several checkboxes whose values are pulled from a specific table of the database. I managed to display them in the form, but cannot insert their values into the table connected to that specific page since there is ony one column.I want to enter all the selected values of the checkbox into that single column separated by commas.

Here's the code:

url <BR><?php $query  = "SELECT url FROM webmeasurements";
$result = mysql_query(开发者_开发百科$query); 
while($row = mysql_fetch_row($result)) 
{     $url  = $row[0];    
echo "<input type=\"checkbox\" name=\"url\" value=\"$row[0]\" />$row[0]<br />";
$checkbox_values = implode(';', $_POST['url']);   }  
?> 

<input type="submit" name="Submit" value="Submit"> 
</form> 
<?php

if(isset($_POST['url']))
{  echo $url;
 foreach ($_POST['url'] as $statename)
 {
   $url=implode(',',$statename)
  }
}
$q="insert into table (url) values ($url)";
?>


You should give each checkbox a different name, not name="url" for all, and then check if(isset($_POST['checkbox_name'])).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜