Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

PHP Implode - Multiple List database entry

Posted on 2007-07-23
3
Medium Priority
?
2,559 Views
Last Modified: 2013-12-12
Problem:
Multiple list inserted into database field as one entry.

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

Code:
<?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);?>
<?php
WA_DFP_SetupUploadStatusStruct("WA_UploadResult1");
if($_SERVER["REQUEST_METHOD"] == "POST"){
      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");
}
?><?php
// 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"]:"")  ."" . "|" . "http://www.sushisushi.com.au/admin/sushisushi/staff/cv/".$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" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<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;
      width:621px;
      height:auto;
      z-index:101;
      left: 154px;
      top: 560px;
      background-color: #FFF;
      background-image:url(images/layerBg.jpg);
      background-position:bottom center;
      background-repeat:no-repeat;
      visibility: hidden;
      border: 1px solid #999999;
}
-->
</style>
<style type="text/css">
<!--
.style4 {
      color: #FFCC66;
      font-weight: bold;
}
-->
</style><?php include("includes/top.inc.php");?>
<div id="main">
<div id="content">
  <div>
    <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
      <hr>
            <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">
      <TR>
        <TD valign="top" style="WIDTH: 239px"><TABLE width="100%" cellPadding="1" cellSpacing="0" class="copydark" id="Table2">
           
            <TR>
              <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>
            </TR>
            <TR>
              <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>
            </TR>
            <TR>
              <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>
            </TR>
            <TR>
              <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>
            </TR>
            <TR>
              <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>
            </TR>
            <TR>
              <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>
            </TR>
            <TR>
              <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>
            </TR>
            <TR>
              <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>
            </TR>
            <TR>
              <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>
            </TR>
            <TR>
              <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>
            </TR>
        </TABLE>
          <p>Please provide us with your CV here:          
          <label><br>
          </label>
          <input name="cv" type="file" size="28">
          </p></TD>
        <TD vAlign="top"><TABLE width="100%" cellPadding="3" cellSpacing="1" class="copydark" id="Table3">
            <TR>
              <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>
            </TR>
            <TR>
              <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>
            </TR>
            <TR>
              <TD colSpan="2" noWrap><P align="center">&nbsp;</P>
                </TD>
              </TR>
            <TR>
              <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>
            <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">
                      <br>
                    Telephone evening
                    <input name="preferredContact" type="radio" value="Tel Eve">
                    <br>
                    Email</span>
                    <input name="preferredContact" type="radio" value="email" checked>
                </P></TD>
            </TR>
        </TABLE></TD>
      </TR>
      <TR class="copydark">
        <TD colSpan="2"><div align="right"> <br>
          <table width="450" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td><div align="center">Please select which restaurant(s) you would<br>
                  be interested in working at: </div></td>
              </tr>
              <tr>
                <td align="center" valign="middle"><label>
                <select name="store" size="10" multiple id="store" style="width:250px">
                  <option value="">Please Select</option>
                  <?php
do {  
?>
                  <option value="<?php echo $row_rs_storefinderSelect['name']?>"><?php echo $row_rs_storefinderSelect['name']?></option>
                  <?php
} 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);
  }
?>
                </select>
                </label></td>
              </tr>
            </table>

            <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>
        </div></TD>
      </TR>
      <TR class="copydark">
        <TD colSpan="2"><p align="center" class="style4">Yes please
              <input name="receiveNews" type="radio" value="yes">
                <br>
          No thank you
          <input name="receiveNews" type="radio" value="no">
        </p>
          <p align="center" class="style4">&nbsp;</p></TD>
      </TR>
      <TR class="copydark">
        <TD colSpan="2"><div align="center">
          <input name="Submit" type="submit" class="buttonAsLink_hover" value="Submit">
        </div></TD>
      </TR>
    </TABLE>
      </form>
    <p align="left">&nbsp;</p>
    <div align="left"></div>
  </div>
  </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 ;?>
</div>
<br clear="all">
</div>
</div><br clear="all">
<?php include("includes/footer.inc.php");?>
  <?php
mysql_free_result($rs_StorefinderInclude);

mysql_free_result($rs_storefinderSelect);
?>

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.
Thanks,
MNEWM
0
Comment
Question by:mnewm
3 Comments
 
LVL 70

Accepted Solution

by:
Jason C. Levine earned 750 total points
ID: 19551916
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...
0
 
LVL 19

Assisted Solution

by:v2Media
v2Media earned 750 total points
ID: 19558896
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 ;?>

to

<?php echo $comma_sep ;?>

0
 

Author Comment

by:mnewm
ID: 19559791
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!
mnewm
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

571 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