473,503 Members | 13,381 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Post multiple items from sel2 with selection in php

2 New Member
I have problem with posting multiple items from sel2 to database without selection.It will so kind from you if you could look my code.
Expand|Select|Wrap|Line Numbers
  1. ///certificate.php
  2. <html>
  3. <head>
  4. <script type="text/javascript" src="stmenu.js"></script>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. </head>
  7. <body>
  8. <form method ="post" action="databasensert.php" enctype="multipart/form-data">
  9.  
  10. <table border="0">
  11. <tr><td><B> Available <br/> Certificates</B></td><td><p></p></td><td><B>Selected<br/> Certificate</B></td></tr>    
  12.  
  13.  
  14. <tr>
  15. <td>
  16. <select name="sel1" style="width:110px" size="15" multiple="multiple">
  17. <?php 
  18. $con = mysql_connect('localhost','root','');
  19. if($con){
  20.                     mysql_select_db('dballiance', $con);
  21. $stmt1 = mysql_query ("select * from certification order by description asc" ) ;
  22. if ( $stmt1 ) {
  23.  
  24. while ( $row1 = mysql_fetch_array( $stmt1 ) ) {
  25. $id = $row1['certification_id'] ;
  26.                             $name = $row1['name'] ;
  27.                              echo "<option value='".$id."'> ".$name." </option>";
  28. }
  29.  }
  30.                     mysql_close($con);
  31. }else{
  32. echo "error.".mysql_error();    
  33. }
  34. ?>
  35.  
  36.  
  37. </select>
  38. </td>
  39. <td align="center">
  40. <input type="button" value="--&gt;"
  41.              onclick="moveOptions(this.form.sel1, this.form.sel2);" /><br />
  42. <input type="button" value="&lt;--"
  43.              onclick="moveOptions(this.form.sel2, this.form.sel1);" />
  44. </td>
  45. <td>
  46. <select name="sel2" style="width:110px" size="15" multiple="multiple">
  47. </select>
  48. </td>
  49. </tr>
  50. </table>
  51. <br/>
  52. <fieldset>
  53. <legend>
  54. Alternative Certificate
  55. </legend>
  56.  
  57.  <table border="0">
  58.       <tr>
  59.         <td>
  60.  
  61.     <p><label for="Name">Name</label><br/>
  62.  
  63.  <input id="Name" maxlength="40" name="Name" autocomplete="off" size="15" type="text" />
  64.          </td>
  65.          <td>
  66. <p><label for="Description">Description</label><br/>
  67.  
  68.           <input id="Description1" maxlength="40" name="Description1" autocomplete="off" size="40" type="text" />
  69.  </td>
  70. </tr>
  71. <tr><td colspan="2"><div align= 'right'>
  72. <input name="Submit" type="Submit" value="Request for creation" ></div> </td>
  73.           </tr>
  74.           </table>
  75. </fieldset>
  76.  
  77.  
  78. <table border = "0" align ="right"> 
  79. <tr>
  80. <td>
  81.  
  82. <input name="button" type="button" value="Back" ONCLICK="window.location.href='service.php'">
  83. </td>
  84. <td>
  85. <div><input id="Submit" name="Submit" type="Submit" value="Submit">
  86. </div>
  87. </td>
  88. </tr>
  89. </table>
  90.  
  91.  
  92.  
  93.  
  94.  
  95.   <!-- JavaScript code -->
  96.  
  97.  
  98.  
  99.  
  100.  
  101. <script language="JavaScript">
  102. var NS4 = (navigator.appName == "Netscape" && parseInt(navigator.appVersion) < 5);
  103.  
  104. function addOption(theSel, theText, theValue)
  105. {
  106.     var newOpt = new Option(theText, theValue);
  107.     var selLength = theSel.length;
  108.     theSel.options[selLength] = newOpt;
  109. }
  110.  
  111. function deleteOption(theSel, theIndex)
  112. {    
  113.     var selLength = theSel.length;
  114.     if(selLength>0)
  115.     {
  116.         theSel.options[theIndex] = null;
  117.     }
  118. }
  119.  
  120. function moveOptions(theSelFrom, theSelTo)
  121. {
  122.  
  123.     var selLength = theSelFrom.length;
  124.     var selectedText = new Array();
  125.     var selectedValues = new Array();
  126.     var selectedCount = 0;
  127.  
  128.     var i;
  129.  
  130.     // Find the selected Options in reverse order
  131.     // and delete them from the 'from' Select.
  132.     for(i=selLength-1; i>=0; i--)
  133.     {
  134.         if(theSelFrom.options[i].selected)
  135.         {
  136.             selectedText[selectedCount] = theSelFrom.options[i].text;
  137.             selectedValues[selectedCount] = theSelFrom.options[i].value;
  138.             deleteOption(theSelFrom, i);
  139.             selectedCount++;
  140.         }
  141.     }
  142.  
  143.     // Add the selected text/values in reverse order.
  144.     // This will add the Options to the 'to' Select
  145.     // in the same order as they were in the 'from' Select.
  146.     for(i=selectedCount-1; i>=0; i--)
  147.     {
  148.         addOption(theSelTo, selectedText[i], selectedValues[i]);
  149.     }
  150.  
  151.     if(NS4) history.go(0);
  152. }
  153. </script>
  154.  
  155. </form>
  156.  
  157. </body>
  158. </html>


Expand|Select|Wrap|Line Numbers
  1. ///databaseinsert.php
  2. <?php
  3.  
  4. //$Name=trim($_POST["Name"]);
  5. //$Description=trim($_POST["Description1"]);
  6. //$query="INSERT INTO alternative_certificate (certificate_id,name,description) VALUES ('', '".$Name."','".$Description."')";
  7.  
  8. $CertId=trim($_POST["sel1"]);
  9. while (list ($val) = @each ($CertId)) {
  10. echo "Certificate_id: ".$val."</br>";
  11. }
  12.  
  13. $con = mysql_connect('localhost','root','');
  14. if($con){
  15.                     mysql_select_db('dballiance', $con);
  16. $stmt = mysql_query ("select * from certification order by description asc" ) ;
  17. while ( $row = mysql_fetch_array( $stmt ) ) {
  18. echo $row['certification_id'];
  19.                             $query="INSERT INTO partner_certification (partner_id,certification_id) VALUES ('4','".$CertId."')";
  20.                             echo $query;
  21.                             mysql_query($query);
  22.                          }        
  23.  
  24. mysql_close($con);
  25.  
  26. }else{
  27. echo "error.".mysql_error();    
  28. }
  29.  
  30. //echo "<script>document.location.href='summary.php'</script>";
  31. ?>
  32.  


Expand|Select|Wrap|Line Numbers
  1. ///database Script
  2.  
  3.  
  4. # --------------------------------------------------------
  5. # Host:                         127.0.0.1
  6. # Database:                     dballiance
  7. # Server version:               5.1.41
  8. # Server OS:                    Win32
  9. # HeidiSQL version:             5.0.0.3272
  10. # Date/time:                    2010-06-11 01:40:07
  11. # --------------------------------------------------------
  12.  
  13.  
  14. # Dumping database structure for dballiance
  15. CREATE DATABASE IF NOT EXISTS `dballiance` /*!40100 DEFAULT CHARACTER SET latin1 */;
  16. USE `dballiance`;
  17.  
  18.  
  19. # Dumping structure for table dballiance.alternative_certificate
  20. CREATE TABLE IF NOT EXISTS `alternative_certificate` (
  21.   `certificate_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  22.   `name` varchar(20) NOT NULL,
  23.   `description` varchar(255) NOT NULL,
  24.   `partner_id` tinyint(3) unsigned NOT NULL,
  25.   PRIMARY KEY (`certificate_id`)
  26. ) ENGINE=MyISAM AUTO_INCREMENT=42 DEFAULT CHARSET=latin1;
  27.  
  28.  
  29.  
  30.  
  31. # Dumping structure for table dballiance.certification
  32. CREATE TABLE IF NOT EXISTS `certification` (
  33.   `certification_id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  34.   `name` varchar(45) NOT NULL,
  35.   `description` varchar(255) DEFAULT NULL,
  36.   PRIMARY KEY (`certification_id`)
  37. ) ENGINE=MyISAM AUTO_INCREMENT=9 DEFAULT CHARSET=latin1 COMMENT='\r\n';
  38.  
  39.  
  40.  
  41.  
  42.  
  43. # Dumping structure for table dballiance.partner_certification
  44. CREATE TABLE IF NOT EXISTS `partner_certification` (
  45.   `partner_id` int(10) unsigned NOT NULL,
  46.   `certification_id` int(10) unsigned NOT NULL,
  47.   `name` varchar(10) DEFAULT NULL,
  48.   PRIMARY KEY (`partner_id`,`certification_id`),
  49.   KEY `partner_has_Certification_FKIndex1` (`partner_id`),
  50.   KEY `partner_has_Certification_FKIndex2` (`certification_id`)
  51. ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Jul 5 '10 #1
1 2201
dlite922
1,584 Recognized Expert Top Contributor
I don't know what you're looking for. You will continue to be ignored for a few reasons:

1. Not clearly explaining your problem.

2. Not using proper forum etiquette and not using code tags.

3. Expecting someone to trace and fix your entire code for you, for free, using their time.

Try again,


Dan
Jul 9 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

0
1506
by: Sylwia | last post by:
Hi! Have anyone ever tried to modify the Gene Cash's Tkinter tree widget (available from http://home.cfl.rr.com/genecash/) so it supports multiple items selection ( selection of multiple files...
0
2066
by: Ringwraith | last post by:
Hi! Have anyone ever tried to modify the Gene Cash's Tkinter tree widget (available from http://home.cfl.rr.com/genecash/) so it supports multiple items selection ( selection of multiple files...
1
2899
by: sneha123 | last post by:
There will be some 20 questions and for each question there will be 4 choices.what i want to do is to select multiple answers by clicking the checkbox. i m using asp.net,vb.net pls help me we...
3
7358
by: Dany P. Wu | last post by:
Hi everyone, One of my Windows forms contain two listbox controls, with Add and Remove buttons between them. The idea is to allow users to select multiple items from one ListBox, click the...
2
8123
by: anchi.chen | last post by:
Hi People, Just wondering if any of you have ever come across any javascript examples that will allow one to drag and drop multiple items between lists? That is, users would be able to use the...
5
1703
by: rameshbhojan | last post by:
Hi All, Please let me know if there is way in which i we can make multiple selections from a drop down list. The requirement is as follows: I have a drop down list, whose entries are to be...
2
15243
by: =?Utf-8?B?S3Jpc2huYQ==?= | last post by:
Hi, I am devloping one web application using .net framework 2.0.One page has 7 dropdown list control.When i update the values first bind the values to the drop down llist then selected text...
1
2061
by: c35tar1 | last post by:
I have a ListView within a dialog. In code the groups are created and items added. Display is 100% correct. The problem is with using Shift to select multiple items in the list. - If you...
5
2394
by: littlegreen | last post by:
Hi all, I'm having the problem while using the edit-in-place scripts from internet. It's ok when i just used for one text id, but after i added a while loop because of multiple items and it become...
4
2208
by: swethak | last post by:
hi i wrote a code to select multiple items in a drop down list.And i store all the items in my database.But in that i select multiple items and submit that items last item only stored.Please...
0
7212
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7296
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7470
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
5026
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4696
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3186
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3174
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1524
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.