Friday, April 3, 2015

implode function : How to send mulitple values in single field


now i am going to show you how to insert multiple values... 

e.g. like user select multiple checkbook and you need to save in a single field in table.
like below user select multiple choice..

then database must store all values in single table cell. like below.


so here is an example of above program.

<form action="" method="post">
<br /><br />What's your favorite programming language?<br />
<input type="checkbox" name="languages[]" value="csharp" />C#<br />
<input type="checkbox" name="languages[]" value="jscript" />JavaScript<br />
<input type="checkbox" name="languages[]" value="perl" />Perl<br />
<input type="checkbox" name="languages[]" value="php" />PHP<br /><br />
<input type="submit" name="submit" value="Go!" />
</form>

<?php
include("connection.php");

//here we use the php in build function of implode

$checkbox=implode(', ',$_POST['languages']);

if (isset($_POST['submit']))
{
foreach($_POST['languages'] AS $lang) echo $lang ."<br />";
}
$qry=mysql_query("INSERT INTO student (language) VALUES ('".$checkbox."')");


?>


No comments:

Post a Comment