Page 1 of 1

multiple size select list to send to mySQL db

Posted: Fri Sep 21, 2012 8:58 am
by jonnyfortis
Hello i have made a form that has a select list showing products

Code: Select all

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
  $insertSQL = sprintf("INSERT INTO beauStock (StockID, ID, SizeID) VALUES (%s, %s, %s)",
                       GetSQLValueString($_POST['StockID'], "int"),
                       GetSQLValueString($_POST['ID'], "text"),
                       GetSQLValueString($_POST['SizeID'], "text"));

  mysql_select_db($database_beau, $beau);
  $Result1 = mysql_query($insertSQL, $beau) or die(mysql_error());

  $insertGoTo = "size-list.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

mysql_select_db($database_beau, $beau);
$query_Recordset1 = "SELECT * FROM beauProd";
$Recordset1 = mysql_query($query_Recordset1, $beau) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);

mysql_select_db($database_beau, $beau);
$query_Recordset2 = "SELECT * FROM beauSizeList";
$Recordset2 = mysql_query($query_Recordset2, $beau) or die(mysql_error());
$row_Recordset2 = mysql_fetch_assoc($Recordset2);
$totalRows_Recordset2 = mysql_num_rows($Recordset2);

<select id="ID" name="ID">
    <option value="select product name">select product name</option>
    <?php
do { 
?>
    <option value="<?php echo $row_Recordset1['ID']; ?>"><?php echo $row_Recordset1['name']; ?></option>
    <?php
} while ($row_Recordset1 = mysql_fetch_assoc($Recordset1));
  $rows = mysql_num_rows($Recordset1);
  if($rows > 0) {
      mysql_data_seek($Recordset1, 0);
            $row_Recordset1 = mysql_fetch_assoc($Recordset1);
  }
?>
    </select>

<select name="SizeID">
    <option value="select Size">Select Size</option>
    <?php
do { 
?>
    <option value="<?php echo $row_Recordset2['SizeID']; ?>"><?php echo $row_Recordset2['Size']; ?></option>
    <?php
} while ($row_Recordset2 = mysql_fetch_assoc($Recordset2));
  $rows = mysql_num_rows($Recordset2);
  if($rows > 0) {
      mysql_data_seek($Recordset2, 0);
            $row_Recordset2 = mysql_fetch_assoc($Recordset2);
  }
?>
    </select>
an i currently have a select list showing size and can pnly select one at a time. how do i make a multiple select list that when sent will add the data to the correct feilds in the db (this being the feilds in Recordset2)

thanks in advance

Re: multiple size select list to send to mySQL db

Posted: Fri Sep 21, 2012 11:34 am
by Celauran

Re: multiple size select list to send to mySQL db

Posted: Sat Sep 22, 2012 3:26 am
by jonnyfortis
found out how to do it

at the end of the select name with a [] e.g <select name="SizeID[]" multiple="multiple">

and in the php code add

if (isset($_POST['SizeID'])) {
$_POST['SizeID'] = implode(',', $_POST['SizeID']);
}

this does however put all the content in one field. Im not sure if this is correct

Re: multiple size select list to send to mySQL db

Posted: Sat Sep 22, 2012 7:55 pm
by califdon
That's probably not going to give you what you want. Check this out: http://stackoverflow.com/questions/2407 ... box-in-php

Re: multiple size select list to send to mySQL db

Posted: Mon Oct 01, 2012 1:39 pm
by jonnyfortis
i have looked at this but i really need to the sizes to be sent to the DB and given there own unqiue ID's