php - Multiple dropdown values inserting in a single row not in multiple row -


in code when selected multiple values dropdown stoing in single row apply value in each row please me. actual result:

id    game 1.    cricket,football,tennis 

expecting result:

id         game 1            cricket 2            football 

code -

                <html>                 <body>                   <?php                      if(isset($_post['submit']))                      {                     $query=mysql_connect('localhost','root','');                        mysql_select_db("freeze",$query);                        $choice=$_post['game'];                       $choice1=implode(',',$choice);                       mysql_query("insert tb values('','$choice1')");                          }                       ?>                         <form method="post" action="multipleselect.php">                            select favourite game:<br/>                         <select name="game[]" multiple="multiple">                               <option>football</option>                                    <option>volleyball</option>                                        <option>badminton</option>                                         <option>cricket</option>                                            <option>cricket1</option>                                              <option>cricket2</option>                                              <option>cricket3</option>                                                  <option>cricket34</option>                     </select>              <input type="submit" name="submit">                   </form>                   </body>                  </html> 

it inserting them in 1 row, because imploding $_post['game']

$choice=$_post['game']; $choice1=implode(',',$choice); mysql_query("insert tb values('','$choice1')"); 

you need loop on each $_post['game'] value

foreach($_post['game'] $choice){     mysql_query("insert tb values('','$choice')"); } 

note, query open sql injection, make sure sanitize data before inserting db. also, mysql_* deprecated, should update mysqli or pdo - http://php.net/manual/en/mysqlinfo.api.choosing.php


Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -