Ver Mensaje Individual
  #1 (permalink)  
Antiguo 16/03/2010, 04:09
Induma
 
Fecha de Ingreso: enero-2004
Ubicación: en mi casa
Mensajes: 29
Antigüedad: 20 años, 3 meses
Puntos: 1
array+php+mysql, un empujoncito?

muy buenas a todos
tengo el siguiente codigo, creado con dreamweaver, y funciona todo perfecto excepto los checkbox, que no soy capaz de introducirlos en la BD, como el resto de datos.

Código:
<?php require_once('Connections/xxxx.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}


if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form2")) {

$insertSQL = sprintf("INSERT INTO xxxx (campos) VALUES (valores)",
GetSQLValueString($_POST['numero'], "int"),
GetSQLValueString($_POST['nombre'], "text"),
GetSQLValueString($_POST['seleccion'], "text"),
GetSQLValueString($_POST['observaciones'], "text"),
GetSQLValueString($_POST['fecha'], "date"));
mysql_select_db($database_xxxx, $xxxx);
$Result1 = mysql_query($insertSQL, $xxxx) or die(mysql_error());

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

mysql_select_db($database_xxxx, $xxxx);
$query_Recordset1 = "SELECT * FROM xxxx";
$Recordset1 = mysql_query($query_Recordset1, $xxxx) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?><!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=utf-8">
<title>Documento sin t&iacute;tulo</title>
</head>

<body>
<div>
<?php
if(isset($_POST['insertar registro']))
foreach($_POST['tratamiento_id'] as $tratamiento)
$tratamiento=serialize(",",$_POST['tratamiento']);
?>
<form method="POST" name="form2" action="<?php echo $editFormAction; ?>">
<table align="center">
<tr valign="baseline">
<td width="126" align="right" nowrap>Numero:</td>
<td width="243"><input type="text" name="historia" size="8"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Nombre:</td>
<td><input type="text" name="nombre" size="32"></td>
</tr>
<tr valign="baseline">
<td align="right" valign="middle" nowrap>Eleccion:</td>
<td>

<input name="tratamiento_id[]" type="checkbox" value="opcion 1">&nbsp;opcion 1&nbsp;&nbsp;
<input name="tratamiento_id[]" type="checkbox" value="opcion 2">&nbsp;opcion 2<br>
<input name="tratamiento_id[]" type="checkbox" value="opcion 3">&nbsp;opcion 3&nbsp;&nbsp;
<input name="tratamiento_id[]" type="checkbox" value="opcion 4">&nbsp;opcion 4<br>
<input name="tratamiento_id[]" type="checkbox" value="opcion 5">&nbsp;opcion 5&nbsp;&nbsp;
<input name="tratamiento_id[]" type="checkbox" value="opcion 6">&nbsp;opcion 6<br>
<input name="tratamiento_id[]" type="checkbox" value="opcion 7">&nbsp;opcion 7 </td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Seleccion:</td>
<td><select name="seleccion">
<option value="" selected>Seleciona</option>
<option value="opcion 1">opcion 1</option>
<option value="opcion 2">opcion 2</option>
<option value="opcion 3">opcion 3</option>
<option value="opcion 4">opcion 4</option>
<option value="opcion 5">opcion 5</option>
<option value="opcion 6">opcion 6</option>
<option value="opcion 7">opcion 7</option>
<option value="opcion 8">opcion 8</option>
<option value="opcion 9">opcion 9</option>
</select></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Fecha:</td>
<td><input type="text" name="fecha" size="32"></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">Observaciones:</td>
<td><textarea name="observaciones" cols="32"></textarea></td>
</tr>
<tr valign="baseline">
<td nowrap align="right">&nbsp;</td>
<td><input type="submit" value="Insertar registro"></td>
</tr>
</table>
<input type="hidden" name="MM_insert" value="form2">
</form>


</div>

</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
yo se que el fallo esta en este trozo de codigo,
Código:
if(isset($_POST['insertar registro']))
foreach($_POST['tratamiento_id'] as $tratamiento)
$tratamiento=serialize(",",$_POST['tratamiento']);
pero por mas vueltas que le doy no consigo hacerlo funcionar.
alguien podria echarme una manita?
un millon de gracias por adelantado