Greetings from the 3rd World.
I’m by no means an experienced php writer or even the worse writer, as sad as it seems i’m nothing but a poser, but willing to learn.
on the past days i’ve benn struggling with something like’s described on this thread but seems that my lack of knowleadge is so great that i can’t get to understand the examples. (i’ve been searching all over the net for this answer for almost two months now.)
The Issue:
I have an Indert Record page to submit data to a MySQL database and a couple of fields have the option for the user to insert more than one value into it and i’m baking my brains off to figure out how, cos (as u all might already know very well) a regular select box or group of checkboxes only post the last value in the array selected. So i heard from a dude that the answer is an array, but the best i cud get is to post into the table the word “ARRAY” instead of my values.
This is what i’m doing (the actual table contains 32 fields to fill up, so i will post just a few, i’ll fill the blanks later)
For the HEAD tag of the PHP page:
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
$insertSQL = sprintf("INSERT INTO Clientes (client_id, Nombre, Keywords, playera, aplicaciones, aplicOp, otros, logoLink) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['client_id'], "int"),
GetSQLValueString($_POST['Nombre'], "text"),
GetSQLValueString($_POST['Keywords'], "text"),
GetSQLValueString($_POST['playera[]'], "text"),
GetSQLValueString(isset($_POST['aplicaciones']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['aplicOp']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString(isset($_POST['otros']) ? "true" : "", "defined","'Y'","'N'"),
GetSQLValueString($_POST['logoLink'], "text"));
mysql_select_db($database_playerasConn, $playerasConn);
$Result1 = mysql_query($insertSQL, $playerasConn) or die(mysql_error());
$insertGoTo = "agregado.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
and for the BODY:
<form method="post" name="form" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td align="right" valign="top" nowrap class="smallTitleBold">Nombre:</td>
<td valign="top" class="normal"><input name="Nombre" type="text" class="normal" value="" size="30" maxlength="60"></td>
</tr>
<tr valign="baseline">
<td align="right" valign="top" nowrap class="smallTitleBold">Keywords:</td>
<td valign="top" class="normal"><textarea name="Keywords" cols="40" rows="5" class="normal"></textarea> </td>
</tr>
<tr valign="baseline">
<td align="right" valign="top" nowrap class="smallTitleBold">Playera:</td>
<td valign="top" class="normal">
<select name="playera[]" size="5" multiple="multiple" class="normal" id="playera[]">
<?php
do {
?>
<option value="<?php echo $row_rsPlayeras['valor']?>"><?php echo $row_rsPlayeras['nombre']?></option>
<?php
} while ($row_rsPlayeras = mysql_fetch_assoc($rsPlayeras));
$rows = mysql_num_rows($rsPlayeras);
if($rows > 0) {
mysql_data_seek($rsPlayeras, 0);
$row_rsPlayeras = mysql_fetch_assoc($rsPlayeras);
}
?>
</select></td>
</tr>
<tr valign="baseline">
<td align="right" valign="top" nowrap class="smallTitleBold">Aplicaciones:</td>
<td valign="top" class="normal"><input name="aplicaciones" type="checkbox" id="aplicaciones" value="checkbox" /></td>
</tr>
<tr valign="baseline">
<td align="right" valign="top" nowrap class="smallTitleBold">AplicOp:</td>
<td valign="top" class="normal"><input type="checkbox" name="aplicOp" value="" ></td>
</tr>
<tr valign="baseline">
<td align="right" valign="top" nowrap class="smallTitleBold">Otros:</td>
<td valign="top" class="normal"><input type="checkbox" name="otros" value="" ></td>
</tr>
<tr valign="baseline">
<td align="right" valign="top" nowrap class="smallTitleBold"><input type="hidden" name="MM_insert" value="form" />
<input type="hidden" name="client_id" value="" /></td>
<td valign="top" class="normal"><input name="add" type="submit" class="normal" id="add" value="Agregar Registro">
<input name="clear" type="reset" class="normal" id="clear" value="Borrar Forma" /></td>
</tr>
</table>
</form>
Explanation: The selectbox named “playeras” is filled dynamically from another table from the DB (cos is very possible that the options might change on the future) and for this example that’s exactly the one i need to array so the multiple values get posted on the DB table and not just the last selected or the “ARRAY” word.
Any help for a newby?
Please?
i pay on mexican soda.