close ad
WARNING: Do Not Install the DREAMWEAVER CC 2017 Update »
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

form multi select list insert records

Thread began 6/06/2016 3:34 pm by Christopher West | Last modified 9/12/2016 7:19 pm by Christopher West | 1443 views | 41 replies

Christopher WestCommunity Expert

Hi, Its almost working. it does insert the number of items I have selected. however, what its doing is inserted the same ID for all entries. After my test if I select all categories from the list, the ID which is being written to the table is the very first ID from those that I select.

For example is my database table consider of:
CategoryID
6
7
8
9
10

and if I select all the above in my multi-select list then it will create 5 records in the catalog table BUT all with ID 6 being stored.

Here is the code for the insert and the code for the html form:

Chris

php:
<?php

for ($x=0$x<sizeof($_POST['selectedCats']); $x++) {
?>
<?php
if (($_SERVER["REQUEST_METHOD"] == "POST") && (isset($_SERVER["HTTP_REFERER"]) && strpos(urldecode($_SERVER["HTTP_REFERER"]), urldecode($_SERVER["SERVER_NAME"].$_SERVER["PHP_SELF"])) > 0) && isset($_POST)) {
  
$InsertQuery = new WA_MySQLi_Query($ecartdb);
  
$InsertQuery->Action "insert";
  
$InsertQuery->Table "`catalog`";
  
$InsertQuery->bindColumn("CatalogCategoryID""i""".((isset($_POST["selectedCats"]))?implode(",",$_POST["selectedCats"]):"")  ."""WA_DEFAULT");
  
$InsertQuery->bindColumn("CatalogProductID""i""".$_SESSION['ProductID']  ."""WA_DEFAULT");
  
$InsertQuery->saveInSession("CatalogID");
  
$InsertQuery->execute();
  
$InsertGoTo "product-manage.php";
  if (
function_exists("rel2abs")) $InsertGoTo $InsertGoTo?rel2abs($InsertGoTo,dirname(__FILE__)):"";
  
$InsertQuery->redirect($InsertGoTo);
}
?>
<?php
}
?>




php:
<select name="selectedCats[]" style="width: 260px;" multiple="" class="chosen-select">

  <?php
  
while(!$rsCategory->atEnd()) { //dyn select
  
?> 
    <?php
    
if ("".($rsCategory->getColumnVal("CategoryParentID"))  ."" != "0") {  // WebAssist Show If
    
?>
          <optgroup label="<?php echo($rsCategory->getColumnVal("CategoryID")); ?>">
    <?php
    
// ("".($rsCategory->getColumnVal("CategoryParentID"))  ."" != "0")
    
?>
              <option value="<?php echo($rsCategory->getColumnVal("CategoryID")); ?>"><?php echo($rsCategory->getColumnVal("CategoryName")); ?></option>
          </optgroup>
    <?php
  $rsCategory
->moveNext();
  } 
//dyn select
  
$rsCategory->moveFirst();
  
?>
</select>

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...