PHP Implode - Multiple List database entry

Posted on 2007-07-23
Last Modified: 2013-12-12
Multiple list inserted into database field as one entry.

I can insert the last choice selected from the multiple list, and have had no success with PHP implode. What am I missing?

<?php require_once('Connections/conn_SushiSUshi.php'); ?>
<?php require_once("WA_DataAssist/WA_AppBuilder_PHP.php"); ?>
<?php require_once("WA_DigitalFilePro/HelperPHP.php"); ?>
<?php $array_stores = array('store');
$comma_sep = implode(",", $array_stores);

mysql_select_db($database_conn_SushiSUshi, $conn_SushiSUshi);
$query_rs_StorefinderInclude = "SELECT ID, name FROM storefinder ORDER BY name ASC";
$rs_StorefinderInclude = mysql_query($query_rs_StorefinderInclude, $conn_SushiSUshi) or die(mysql_error());
$row_rs_StorefinderInclude = mysql_fetch_assoc($rs_StorefinderInclude);
$totalRows_rs_StorefinderInclude = mysql_num_rows($rs_StorefinderInclude);

mysql_select_db($database_conn_SushiSUshi, $conn_SushiSUshi);
$query_rs_storefinderSelect = "SELECT * FROM storefinder ORDER BY name ASC";
$rs_storefinderSelect = mysql_query($query_rs_storefinderSelect, $conn_SushiSUshi) or die(mysql_error());
$row_rs_storefinderSelect = mysql_fetch_assoc($rs_storefinderSelect);
$totalRows_rs_storefinderSelect = mysql_num_rows($rs_storefinderSelect);?>
      WA_DFP_UploadFile("WA_UploadResult1", "cv", "", "../admin/sushisushi/staff/cv/", "".((isset($_POST["fName"]))?$_POST["fName"]:"")  ."".((isset($_POST["lName"]))?$_POST["lName"]:"")  ."", "2", "[FileName]_[Increment]", "0", "false", "0", "0");
// WA Application Builder Insert
if (isset($_POST["Submit"])) // Trigger
  $WA_connection = $conn_SushiSUshi;
  $WA_table = "messageCentre";
  $WA_sessionName = "messageCentre_ID";
  $WA_redirectURL = "sushi-contact-thanks.php";
  $WA_keepQueryString = false;
  $WA_indexField = "ID";
  $WA_fieldNamesStr = "dateSubmitted|store|comment|contactMethod|fName|lName|email|sushiNewsletter|cv|add1|add2|suburb|state|townCity|county|telDay|telEve|postcode";
  $WA_fieldValuesStr = "".((isset($_POST["dateSubmit"]))?$_POST["dateSubmit"]:"")  ."" . "|" . "".((isset($_POST[$comma_sep]))?$_POST[$comma_sep]:"")  ."" . "|" . "".((isset($_POST["message"]))?$_POST["message"]:"")  ."" . "|" . "".((isset($_POST["preferredContact"]))?$_POST["preferredContact"]:"")  ."" . "|" . "".((isset($_POST["fName"]))?$_POST["fName"]:"")  ."" . "|" . "".((isset($_POST["lName"]))?$_POST["lName"]:"")  ."" . "|" . "".((isset($_POST["email"]))?$_POST["email"]:"")  ."" . "|" . "".((isset($_POST["receiveNews"]))?$_POST["receiveNews"]:"")  ."" . "|" . "".$WA_DFP_UploadStatus["WA_UploadResult1"]["serverFileName"]  ."" . "|" . "".((isset($_POST["add1"]))?$_POST["add1"]:"")  ."" . "|" . "".((isset($_POST["add2"]))?$_POST["add2"]:"")  ."" . "|" . "".((isset($_POST["suburb"]))?$_POST["suburb"]:"")  ."" . "|" . "".((isset($_POST["state"]))?$_POST["state"]:"")  ."" . "|" . "".((isset($_POST["townCity"]))?$_POST["townCity"]:"")  ."" . "|" . "".((isset($_POST["county"]))?$_POST["county"]:"")  ."" . "|" . "".((isset($_POST["telDay"]))?$_POST["telDay"]:"")  ."" . "|" . "".((isset($_POST["telEve"]))?$_POST["telEve"]:"")  ."" . "|" . "".((isset($_POST["postcode"]))?$_POST["postcode"]:"")  ."";
  $WA_columnTypesStr = "',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''|',none,''";
  $WA_fieldNames = explode("|", $WA_fieldNamesStr);
  $WA_fieldValues = explode("|", $WA_fieldValuesStr);
  $WA_columns = explode("|", $WA_columnTypesStr);
  $WA_connectionDB = $database_conn_SushiSUshi;
  mysql_select_db($WA_connectionDB, $WA_connection);
  if (!session_id()) session_start();
  $insertParamsObj = WA_AB_generateInsertParams($WA_fieldNames, $WA_columns, $WA_fieldValues, -1);
  $WA_Sql = "INSERT INTO `" . $WA_table . "` (" . $insertParamsObj->WA_tableValues . ") VALUES (" . $insertParamsObj->WA_dbValues . ")";
  $MM_editCmd = mysql_query($WA_Sql, $WA_connection) or die(mysql_error());
  $_SESSION[$WA_sessionName] = mysql_insert_id();
  if ($WA_redirectURL != "")  {
    if ($WA_keepQueryString && $WA_redirectURL != "" && isset($_SERVER["QUERY_STRING"]) && $_SERVER["QUERY_STRING"] !== "" && sizeof($_POST) > 0) {
      $WA_redirectURL .= ((strpos($WA_redirectURL, '?') === false)?"?":"&").$_SERVER["QUERY_STRING"];
    header("Location: ".$WA_redirectURL);
<?php $relroot = "" ?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Contact SUSHI SUSHI&trade;</title>
<meta name="description" content="Ask us a question - tell us a bout your visit - talk to the SUSHI SUSHIT Chef">
<meta name="keywords" content="Sushi Sushi Chef Platter Victoria Australia Quality Nigiri boxes packs inari plate heroes Broadmeadows Camberwell Centro Box Hill Hawthorn Chadstone Broadmeadows Forest Frankston Highpoint Knox Melbourne Central Northland Prahan The Glen Pines Victoria Gardens Waverly Whitehorse ">
<meta name="robots" content="index,follow">
<script language="javascript" type="text/javascript" src="Scripts/formvalidate_general.js"></script>
<link href="2col_rightNav.css" rel="stylesheet" type="text/css">
<style type="text/css">
.style1 {color: #0081AB}
#shareCare {position:absolute;
      left: 154px;
      top: 560px;
      background-color: #FFF;
      background-position:bottom center;
      visibility: hidden;
      border: 1px solid #999999;
<style type="text/css">
.style4 {
      color: #FFCC66;
      font-weight: bold;
</style><?php include("includes/");?>
<div id="main">
<div id="content">
    <h3> Work at <strong><img src="image/logo.gif" width="200" height="32" alt="Sushi Sushi Chef"></strong></h3>
    <p align="left"><strong><img src="image/chef1.jpg" alt="sushi sushi Chef" width="114" height="133" class="floatleft">Interested in working for  <a href="contact-sushi-sushi-form.php"><strong><img src="image/logoBody.gif" alt="sushi sushi" width="114" height="12" border="0"></strong></a>?</strong><strong> Fill out the form below and someone will get back to you! </strong></p>
    <p>Thank You very much!</p>
    <p><strong><a href="sushi-storefinder.php"><img src="image/logoBody.gif" alt="sushi sushi" width="114" height="12" border="0"></a></strong> Chef
            <form action="<? $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" name="general" id="rateweb" onSubmit="return checkform();">
    <TABLE width="625" cellPadding="1" cellSpacing="1" id="Table1">
        <TD valign="top" style="WIDTH: 239px"><TABLE width="100%" cellPadding="1" cellSpacing="0" class="copydark" id="Table2">
              <TD valign="top" noWrap><P align="right"><font color="#ff0000">
                <input name="dateSubmit" type="hidden" value="<? echo date("D, j/m/y");?>">
              </font>First Name<FONT color="#ff0000">*</FONT></P></TD>
              <TD valign="middle"><input name="fName" type="text" maxlength="50" id="fName" class="CopyDark" /></TD>
              <TD valign="top" noWrap><P align="right">Surname<FONT color="#ff0000">*</FONT></P></TD>
              <TD vAlign="middle"><input name="lName" type="text" maxlength="50" id="lName" class="CopyDark" /></TD>
              <TD valign="top" noWrap><P align="right" >Email Address<FONT color="#ff0000">*</FONT></P></TD>
              <TD vAlign="middle"><input name="email" type="text" maxlength="150" id="email" class="CopyDark" /></TD>
              <TD valign="top" noWrap><P align="right">Address</P></TD>
              <TD vAlign="middle"><input name="add1" type="text" maxlength="50" id="add1" class="CopyDark" /></TD>
              <TD valign="top" noWrap><p align="right">&nbsp;</p></TD>
              <TD vAlign="middle"><input name="add2" type="text" maxlength="50" id="add2" class="CopyDark" /></TD>
              <TD valign="top" noWrap><p align="right">Suburb</p></TD>
              <TD vAlign="middle"><input name="suburb" type="text" maxlength="50" id="suburb" class="CopyDark" /></TD>
              <TD valign="top" noWrap><p align="right">State</p></TD>
              <TD vAlign="middle"><input name="state" type="text" maxlength="50" id="state" class="CopyDark" /></TD>
              <TD valign="top" noWrap><P align="right">Town / City</P></TD>
              <TD vAlign="middle"><input name="townCity" type="text" maxlength="50" id="townCity" class="CopyDark" /></TD>
              <TD valign="top" noWrap><P align="right">County</P></TD>
              <TD vAlign="middle"><input name="county" type="text" maxlength="50" id="county" class="CopyDark" /></TD>
              <TD valign="top" noWrap><P align="right">Post Code</P></TD>
              <TD vAlign="middle"><input name="postcode" type="text" maxlength="10" id="postcode" class="CopyDark" /></TD>
          <p>Please provide us with your CV here:          
          <input name="cv" type="file" size="28">
        <TD vAlign="top"><TABLE width="100%" cellPadding="3" cellSpacing="1" class="copydark" id="Table3">
              <TD valign="middle" noWrap><P align="right">Telephone DAY<FONT color="#ff0000">*</FONT>&nbsp; </P></TD>
              <TD vAlign="middle"><input name="telDay" type="text" maxlength="20" id="txtPhone" class="CopyDark" /></TD>
              <TD valign="middle" noWrap><P align="right">Telephone EVE<FONT color="#ff0000">*</FONT>&nbsp; </P></TD>
              <TD vAlign="middle"><input name="telEve" type="text" maxlength="20" id="txtPhone" class="CopyDark" /></TD>
              <TD colSpan="2" noWrap><P align="center">&nbsp;</P>
              <TD noWrap align="right" colSpan="2">Brief outline of your enquiry<font color="#ff0000">*</font>
                <textarea name="message" cols="25" rows="4" class="CopyDark" id="message"></textarea></TD></TR>
              <TD noWrap colSpan="2"><P align="right"><strong>How would you like us to contact you?</strong></P>
                  <P align="right"><span class="style4">Telephone day
                      <input name="preferredContact" type="radio" value="Tel Day">
                    Telephone evening
                    <input name="preferredContact" type="radio" value="Tel Eve">
                    <input name="preferredContact" type="radio" value="email" checked>
      <TR class="copydark">
        <TD colSpan="2"><div align="right"> <br>
          <table width="450" border="0" align="center" cellpadding="0" cellspacing="0">
                <td><div align="center">Please select which restaurant(s) you would<br>
                  be interested in working at: </div></td>
                <td align="center" valign="middle"><label>
                <select name="store" size="10" multiple id="store" style="width:250px">
                  <option value="">Please Select</option>
do {  
                  <option value="<?php echo $row_rs_storefinderSelect['name']?>"><?php echo $row_rs_storefinderSelect['name']?></option>
} while ($row_rs_storefinderSelect = mysql_fetch_assoc($rs_storefinderSelect));
  $rows = mysql_num_rows($rs_storefinderSelect);
  if($rows > 0) {
      mysql_data_seek($rs_storefinderSelect, 0);
        $row_rs_storefinderSelect = mysql_fetch_assoc($rs_storefinderSelect);

            <hr> <p align="center">Would you like to receive occasional email updates from <strong><a href="sushi-storefinder.php"><img src="image/logoBody.gif" alt="sushi sushi" width="114" height="12" border="0"></a></strong> detailing new dishes, special offers and what else is happening at <strong><a href="sushi-storefinder.php"><img src="image/logoBody.gif" alt="sushi sushi" width="114" height="12" border="0"></a></strong>? </p>
      <TR class="copydark">
        <TD colSpan="2"><p align="center" class="style4">Yes please
              <input name="receiveNews" type="radio" value="yes">
          No thank you
          <input name="receiveNews" type="radio" value="no">
          <p align="center" class="style4">&nbsp;</p></TD>
      <TR class="copydark">
        <TD colSpan="2"><div align="center">
          <input name="Submit" type="submit" class="buttonAsLink_hover" value="Submit">
    <p align="left">&nbsp;</p>
    <div align="left"></div>
<div id="navBar">
<div align="center"><strong><br>
      Select your<br>
      <img src="<?php echo $relroot?>image/logoBody.gif" width="114" height="12" alt="sushi sushi"></strong> <strong>Store</strong>:    </div>
          <div align="left" style="font-size:80%"><p><?php do { ?>
           <a href="sushi-storefinder-results.php?S_ID=<? echo $row_rs_StorefinderInclude['ID']; ?>"><?php echo $row_rs_StorefinderInclude['name']; ?></a><br>
            <?php } while ($row_rs_StorefinderInclude = mysql_fetch_assoc($rs_StorefinderInclude)); ?></div>
          <? echo $comma_sep ;?>
<br clear="all">
</div><br clear="all">
<?php include("includes/");?>


Downloaded a Dreamweaver extension which puts multiple lists into an array, but no way of referencing it. The extension puts the following code in the header:
if (isset($_POST["store"]) && is_array($_POST["store"])) {
  $_POST["store"] = implode(",", $_POST["store"]);
  $HTTP_POST_VARS["store"] = $_POST["store"];

Could I reference this code to enter into the database? The 'store' field wants to go into a database 'cell' for the row as a list (preferably comma separated) and will need exploding again.

Any help appreciated.
Question by:mnewm
    LVL 70

    Accepted Solution

    Hi mnewm,

    I think you need to change the HTML name of the list box to "store[]" so the multiple values will get stored as an array upon posting.

    That should allow the last code fragment to combine all selected values into one...
    LVL 19

    Assisted Solution

    I agree with Jason, change the select's html to:

    <select name="store[]" size="10" multiple id="store[]" style="width:250px">

    However in reading the script through, I thought I'd mention that you have a php short tag in there. If you want your code to work on another server where php short tags are disabled, change your php tags to long versions. For eg:

    <? echo $comma_sep ;?>


    <?php echo $comma_sep ;?>


    Author Comment

    Thanks for your comments! I contacted tech support and they provided me with the solution - but the two of you have contributed.

    jason1178 - you gave half the solution, but I had to include a function I haven't used before - implode. But I won't be forgetting to rename my lists with an extra []!

    v2Media - I'll be tidying my coding up!

    Once again, thanks!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 for Beginning Beginners

    Are you looking for an efficient introduction to HTML5? Have you tried other HTML5 courses and found them too complex? Do you need just the basics of HTML5 to use with Wordpress or other content management system? If you said yes to any of these questions, this course is for you.

    Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
    This article is very specific and is only intended to help if you are installing Dreamweaver 8 in a Windows 7 environment with Office 2007 installed.   I'm not sure why Microsoft tends to release OS' that should not be released but they do.  Windows…
    Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
    This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    11 Experts available now in Live!

    Get 1:1 Help Now