Ver Mensaje Individual
  #1 (permalink)  
Antiguo 18/06/2012, 10:33
marce_vampira
 
Fecha de Ingreso: junio-2012
Ubicación: En Chile :D
Mensajes: 44
Antigüedad: 11 años, 10 meses
Puntos: 0
como guardar usando un for?

hola amigos, tengo un pequeño problema. Yo basicamente hago estas cosas con dreamweaver, pero cuando tengo que meter mano en el codigo quedo corta y no se como avanzar... estuve investigando y para realizar lo que quiero, debo guardar mediante un for, creo... y es ahi donde no se que cosa hacer.... me pueden ayudar porfa?

Tengo esta tabla dentro de un formulario, en la cual es posible marcar varias filas, y todas debo guardarlas en una base de datos

Código PHP:
  <label for="gus"></label>
  <table border="1">
    <tr>
      <td>&nbsp;</td>
      <td>gustos</td>
    </tr>
    <?php 
    $i 
0;
    do { 
    
?>
      <?php echo "<tr><td><input name='obs_".$i."' type='checkbox' id='obs_".$i."' value='".$row_Recordset1[gustos']."'/>
            <
label for='gus_".$i."'></label></td>
            <
td>".$row_Recordset1['gustos']."</td>
            </
tr>";
    $i++; ?>
      <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
  </table>
y este es el codigo con el que guarda los datos en la tabla de la base de datos...

Código PHP:
<?php require_once('Connections/localhost.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function 
GetSQLValueString($theValue$theType$theDefinedValue ""$theNotDefinedValue ""
{
  if (
PHP_VERSION 6) {
    
$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"] == "form1")) {
  
$insertSQL sprintf("INSERT INTO prueba (prueba) VALUES (%s)",
                       
GetSQLValueString($_POST['obs'], "text"));

  
mysql_select_db($database_localhost$localhost);
  
$Result1 mysql_query($insertSQL$localhost) or die(mysql_error());
}
?>
Ojala no sea muy complicado, muchas gracias por su ayuda