By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
426,060 Members | 1,893 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 426,060 IT Pros & Developers. It's quick & easy.

Post multiple items from sel2 with selection in php

P: 2
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
Share this Question
Share on Google+
1 Reply


dlite922
Expert 100+
P: 1,584
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

Post your reply

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