Ver Mensaje Individual
  #1 (permalink)  
Antiguo 26/09/2007, 11:32
ricardomz
 
Fecha de Ingreso: junio-2005
Ubicación: Edo. Mex
Mensajes: 725
Antigüedad: 18 años, 11 meses
Puntos: 5
Sonrisa array en registro mysql

Que tal amigos, tengo una pequeña duda... estoy haciendo un pequeño sistema de registro, y uno de los campos (En este caso en el campo Deporte), el usuario tiene que poder seleccionar mas de una opción en Deporte, es decir tengo que almacenar ese dato como un grupo, es con un array, pero ya me atore con esto.. llevo un ratito con esto y no me sale... hace un tiempo que no lo hacia ...

Les muestro:
Código PHP:
<?php require_once('../Connections/conexion.php'); ?>
<?php
function GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO usuarios (id_user, Nombre, Apellidos, Mail, Edad, Empresa, Dir, Ciudad, Telefono, Deporte, Password) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
                       
GetSQLValueString($_POST['id_user'], "int"),
                       
GetSQLValueString($_POST['Nombre'], "text"),
                       
GetSQLValueString($_POST['Apellidos'], "text"),
                       
GetSQLValueString($_POST['Mail'], "text"),
                       
GetSQLValueString($_POST['Edad'], "text"),
                       
GetSQLValueString($_POST['Empresa'], "text"),
                       
GetSQLValueString($_POST['Dir'], "text"),
                       
GetSQLValueString($_POST['Ciudad'], "text"),
                       
GetSQLValueString($_POST['Telefono'], "text"),
                       
GetSQLValueString($_POST['Deporte'], "text"),
                       
GetSQLValueString($_POST['Password'], "text"));

  
mysql_select_db($database_conexion$conexion);
  
$Result1 mysql_query($insertSQL$conexion) or die(mysql_error());

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

session_start();
$_SESSION['nom']=$_POST['Nombre']; 
$_SESSION['mai']=$_POST['Mail']; 
$_SESSION['pass']=$_POST['Password']; 
?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registro de Usuarios</title>
</head>

<body>
<!-- Formulario del registro -->
Los campos marcados con (*) son obligatorios
<form method="post" name="form1" action="<?php echo $editFormAction?>">
  <table align="center">
    <tr valign="baseline">
      <td nowrap align="right">(*) Nombre:</td>
      <td><input type="text" name="Nombre" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">(*) Apellidos:</td>
      <td><input type="text" name="Apellidos" value="" size="50"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">(*) Mail:</td>
      <td><input type="text" name="Mail" value="" size="50"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Edad:</td>
      <td><input type="text" name="Edad" value="" size="10"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Empresa:</td>
      <td><input type="text" name="Empresa" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Direcci&oacute;n:</td>
      <td><input type="text" name="Dir" value="" size="50"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Ciudad:</td>
      <td><input type="text" name="Ciudad" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Tel&eacute;fono:</td>
      <td><input type="text" name="Telefono" value="" size="16"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">Deporte:</td>
      <td>
      <input type="checkbox" name="Deporte[]" value="Rugby" > 
      Rugby<br />
      <input name="Deporte[]" type="checkbox" value="Vela" />
      Vela<br />
      <label>
      <input name="Deporte[]" type="checkbox" value="Ecuestre" />
      Ecuestre<br />
      <input name="Deporte[]" type="checkbox" value="Tenis" />
      Tenis<br />
      <input name="Deporte[]" type="checkbox" value="Golf" />
      Golf
      </label></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">(*) Password:</td>
      <td><input type="password" name="Password" value="" size="32"></td>
    </tr>
    <tr valign="baseline">
      <td nowrap align="right">&nbsp;</td>
      <td><input type="submit" value="Registrarme"></td>
    </tr>
  </table>
  <input type="hidden" name="id_user" value="">
  <input type="hidden" name="MM_insert" value="form1">
</form>
<p>&nbsp;</p>
<!--Termina formulario del registro -->
</body>
</html>
Gracias de antemano, solo lo que tengo que hacer es mandar correctamente el array, pero estoy atorado, ojala me puedan ayudar..

Les agradezco de antemano, un saludo cordial..

Ricardo.