3 Replies - 460 Views - Last Post: 23 April 2012 - 01:04 PM Rate Topic: -----

#1 richardsith  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-April 12

sending items to db MySQL from second select form

Posted 22 April 2012 - 02:26 PM

Hi everyone,
it's my first post here sorry if I made some issue.
I've a problem with 2 select form and MySQL. The first one lists all items and using 2 buttons you can transfer 'n remove items on the second form. The transfer works well, I'd have to record the idems sent to second form on a db MySQL. I don't know how to make that. 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>


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>

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());
/* -----

This post has been edited by Dormilich: 22 April 2012 - 10:33 PM
Reason for edit:: please use code tags


Is This A Good Question/Topic? 0
  • +

Replies To: sending items to db MySQL from second select form

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 6438
  • View blog
  • Posts: 23,430
  • Joined: 12-June 08

Re: sending items to db MySQL from second select form

Posted 22 April 2012 - 03:08 PM

Moving from java to php.
Was This Post Helpful? 0
  • +
  • -

#3 rpgmaker  Icon User is online

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 217
  • Joined: 02-October 11

Re: sending items to db MySQL from second select form

Posted 22 April 2012 - 03:14 PM

You use
mysql_insert.php:

don't that show a error ? Also
require 'mysql_insert.php';  
you have not shown the coding in the file.


Here is a insert tutorial
http://www.tizag.com...mysqlinsert.php

This post has been edited by rpgmaker: 22 April 2012 - 03:24 PM

Was This Post Helpful? 0
  • +
  • -

#4 richardsith  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 22-April 12

Re: sending items to db MySQL from second select form

Posted 23 April 2012 - 01:04 PM

Maybe I didn't explain that well.
So, my problem is make the transfer of the some items from the first form to the second one and then save the array on db.
The first part makes the transfer, but I don't know how to make for saving the array to db.
With above code I save just the last element and not all.
That has a part written with javascript and is used to make the transfer of the items between forms.

note: the line "require 'mysql_insert.php';" recall an external file that reports the following lines and is used to save item on db:


<?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());
/* ------------------------- */
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1