sending items to db MySQL from the second select form

Discussion in 'JavaScript' started by richardsith, Apr 23, 2012.

  1. #1
    Hello everyone,
    I've a problem with 2 select form and MySQL.
    The first one lists all items, and using 2 buttons I can transfer and remove the items on the second form.
    I'd like that the items (array) transfered on second one go to db MySQL.
    If I select just 1 element from first form I see it on db, but if the selection has more then 2 items I see only the last one selected.
    The transfer between form works well but I'd like to sent more of one idem to db MySQL.
    I don't know how to correct that, may you help me to resolve that,please.

    Below my files.

    index.php:

    <!DOCTYPE html>

    <html lang="en">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    <script language="javascript">

    function getOpt(select1,select2)

    {

    for (bCnt=0;bCnt<select1.length;bCnt++)

    {

    if (select1.options[bCnt].selected)

    {

    newOpt=new

    Option(select1.options[bCnt].text,select1.options[bCnt].value,false,false);

    select2.options[select2.length]=newOpt;

    }

    }

    }


    function remOpt(select2)

    {

    for (bCnt=0;bCnt<select2.length;bCnt++)

    {

    if (select2.options[bCnt].selected)

    select2.options[bCnt]=null;

    }

    }

    </script>

    </head>

    <body>

    <form id="form" action="addring_mysql.php" method="post" name="form1">

    <fieldset>

    <legend id="legend_new">Add Items</legend>





    then the selects form:

    <table border="0">

    <tr>

    <td>

    <label for="id">List:<br></label>

    <select name="oneS" id="select_role" size=20 required multiple="multiple"/>

    <option value="101">101</option>

    <option value="102">102</option>

    <option value="103">103</option>

    <option value="104">104</option>

    <option value="105">105</option>

    <option value="106">106</option>

    </select>

    </td>

    <td>

    <input type="button" value="Add"onClick="getOpt(this.form.oneS,this.for m.twoS)"><br>

    <input type="button" value="Remove"onClick="remOpt(this.form.twoS)">

    </td>

    <td>

    <label for="id">Members List:<br></label>

    <select name="twoS" id="select_role" size=20 multiple="multiple"/>

    </select>

    </td>

    </tr>

    </table>

    </fieldset>

    <p id="submit">

    <input type="submit" value="Save" />

    </p>

    </form>

    </body>

    </html>





    and addring_mysql.php:

    <!DOCTYPE html>

    <html lang="en">

    <head>

    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

    </head>


    <body onload="window.close()">


    <?php

    /* -------------------------------------------------------------------------- */

    require 'mysql_connect.php';

    require 'mysql_insert.php';

    /* -------------------------------------------------------------------------- */

    ?>

    </body>

    </html>





    and mysql_insert.php:


    <?php
    $db_insert = mysql_query("INSERT INTO ring (id,ring,oneS) VALUES ('$id','$ring','oneS')") or die ("Error to insert the VoIP account to table users by query: " . mysql_error());

    ?>





    thanks a lot in advance.
     
    richardsith, Apr 23, 2012 IP