Ver Mensaje Individual
  #20 (permalink)  
Antiguo 06/05/2011, 18:20
osafado
 
Fecha de Ingreso: septiembre-2010
Mensajes: 92
Antigüedad: 13 años, 7 meses
Puntos: 1
Respuesta: insertar en datatabase solo filas no vacias...

Hola angelfcm, que pena contigo, de verdad me equivoqué con el archivo...
De toda forma imagina que copié el archivo correcto y seguía con los errores, tuve que hacer una cosa rara; borrar los espacios vacíos y volver a poner en su lugar el código, así desaparecían los errores. aun así sin darme ningún error el script no me inserta ningún datos en la base de datos (disculpa la redundancia). aqui te pongo los script:

************************************************** **
Código PHP:
<?php include ("../conexion.php");
 
<
form action="pruebaelaboradatos1.php" method="post" onsubmit="buscarChecks(this)">
<
input type="hidden" name="numchecks" value="0" />
<?
php header("Content-type:text/html;charset=ISO-8859-1");
//***************************************************************************
/* Realizamos la consulta SQL */
$sql"SELECT  e_nombre  FROM estudiantes WHERE (id=19)  ";

$resultmysql_query($sql) or die(mysql_error());
if(
mysql_num_rows($result)==0) die("No hay registros para mostrar");    
//**********************************************************************
$sql2"SELECT  ob1,  ob2,  ob3,  ob4,  ob5,  ob6,  ob7,  ob8,  ob9,  ob10,  ob11,  ob12,  ob13,  ob14  FROM objetivos WHERE id=6 ";
$result2mysql_query($sql2) or die(mysql_error());
if(
mysql_num_rows($result2)==0) die("No hay registros para mostrar");    
//*************************************************************************


echo "<table border=1 cellpadding=1 cellspacing=0>";
echo 
"<tr><th colspan=18><center>  GRUPO SEXTO A 'MATEMATICAS'</th><tr>";

# construyendo los encabezados de la tabla
echo " <th bgcolor=silver><font size=1 ><center>___________ESTUDIANTE___________</font></th>
<th bgcolor=silver><font size=1 ><center>01</font></th>
<th bgcolor=silver><font size=1 ><center>02</font></th>
<th bgcolor=silver><font size=1 ><center>03</font></th>
<th bgcolor=silver><font size=1 ><center>04</font></th>
<th bgcolor=silver><font size=1 ><center>05</font></th>
<th bgcolor=silver><font size=1 ><center>06</font></th>
<th bgcolor=silver><font size=1 ><center>07</font></th>
<th bgcolor=silver><font size=1 ><center>08</font></th>
<th bgcolor=silver><font size=1 ><center>09</font></th>
<th bgcolor=silver><font size=1 ><center>10</font></th>
<th bgcolor=silver><font size=1 ><center>11</font></th>
<th bgcolor=silver><font size=1 ><center>12</font></th>
<th bgcolor=silver><font size=1 ><center>13</font></th>
<th bgcolor=silver><font size=1 ><center>14</font></th>
<th bgcolor=silver><font size=1 ><center>Nota</font></th>
<th bgcolor=silver><font size=1 ><center>Juicio Valorativo</font></th>
<th bgcolor=silver><font size=1 ><center></font></th></TR>"
;
//*************************************************************************
/*Y ahora todos los registros */
while($row2=mysql_fetch_array($result2))

 

while(
$row=mysql_fetch_array($result))

//*****************************************************
{
echo 
"<tr>
<td> $row[e_nombre] </td>
<td>"
; if($row2['ob1'] != ""){ echo "<input type='checkbox' name=c1 value=1 >"; } else{ echo ""; } echo "</td>
<td>"
; if($row2['ob2'] != ""){ echo "<input type='checkbox' name=c2 value=1 >"; } else{ echo ""; } echo "</td>
<td>"
; if($row2['ob3'] != ""){ echo "<input type='checkbox' name=c3 value=1 >"; } else{ echo ""; } echo "</td>
<td>"
; if($row2['ob4'] != ""){ echo "<input type='checkbox' name=c4 value=1 >"; } else{ echo ""; } echo "</td>
<td>"
; if($row2['ob5'] != ""){ echo "<input type='checkbox' name=c5 value=1 >"; } else{ echo ""; } echo "</td>
<td>"
; if($row2['ob6'] != ""){ echo "<input type='checkbox' name=c6 value=1 >"; } else{ echo ""; } echo "</td>
<td>"
; if($row2['ob7'] != ""){ echo "<input type='checkbox' name=c7 value=1 >"; } else{ echo ""; } echo "</td>
<td>"
; if($row2['ob8'] != ""){ echo "<input type='checkbox' name=c8 value=1 >"; } else{ echo ""; } echo "</td>
<td>"
; if($row2['ob9'] != ""){ echo "<input type='checkbox' name=c9 value=1 >"; } else{ echo ""; } echo "</td>
<td>"
; if($row2['ob10'] != ""){ echo "<input type='checkbox' name=c10 value=1 >"; } else{ echo ""; } echo "</td>
<td>"
; if($row2['ob11'] != ""){ echo "<input type='checkbox' name=c11 value=1 >"; } else{ echo ""; } echo "</td>
<td>"
; if($row2['ob12'] != ""){ echo "<input type='checkbox' name=c12 value=1 >"; } else{ echo ""; } echo "</td>
<td>"
; if($row2['ob13'] != ""){ echo "<input type='checkbox' name=c13 value=1 >"; } else{ echo ""; } echo "</td>
<td>"
; if($row2['ob14'] != ""){ echo "<input type='checkbox' name=c14 value=1 >"; } else{ echo ""; } echo "</td>
<td> <input name='nota3' type='text' id='nota3' size='10' maxlength='10' /> </td>
<td> <input name='juicio' type='text' id='juicio' size='40' maxlength='150' /> </td>
<td> <input type='submit' name='button' id='button' value='Enviar' /> </td>
</tr>"
;
}
echo 
"</table>";  

?>
<script>
function buscarChecks(Form){
 var numchecks=0;
 for(x=0;x<Form.childNodes.length;x++){
 var nodo=Form.childNodes[x];
 if(nodo.type=='checkbox' && /^c([0-9]+)$/i.test(nodo.name))
 numchecks++ }
 Form.numchecks.value=numchecks;
}
</script>
*************************************************

Otro script que inserta (pruebaelaboradatos1.php)

*************************************************
Código PHP:
<?php include ("../conexion.php");
 
///////////////////////////////////////////////////////////////////////////////////////////////////////////// 
# post & checkbox
$nota3 $_POST['nota3'];
$val $_POST['val']; 
$juicio $_POST['juicio']; 
$numChecks $_POST['numChecks'];
$maxChecks=14;
$consultaChecks="";
for(
$x=1;$x<=$maxChecks;$x++){
    if(
$x<=$numChecks)
    eval(
"\$actual=\$_POST[c".$x."]?'F':'D';");
    else 
$actual="";
    if(
$consultaChecks)
    
$consultaChecks.=", c".$x."='".$actual."'";
    else 
$consultaChecks="c1='".$actual."'";
    }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////// 
# valoracion 
$val=($nota3!="" && $nota3<3.0)?
     
"bajo":
    (
    (
$nota3>=3.0 && $nota3<=3.6)?
    
"básico":
    (
    (
$nota3>=3.7 && $nota3<=4.3)?
     
"alto":
     
"superior"
     
)
     ); 

 
$sql "UPDATE SEXTO_A_MAT SET ".$consultaChecks.", 
 nota3='$nota3', val='$val' , juicio='$juicio' *
 WHERE id=1"

$result mysql_query($sql);
mysql_close(); 
//////////////////////////////////////////////////////////////////////////////////////////////////////////////// 

echo "<center> datos insertados con exito </center>"
?>
<style type="text/css">
.font {
    font-family: Verdana, Geneva, sans-serif;
    font-size: 16px;
    color: #F00;
}
</style>

 <center><a href="javascript:history.back(1)" class="font">Volver Atrás</a></center>
La unica cosa que cambié fué esto:

$numChecks=$_POST[numchecks];

Con

$numChecks = $_POST['numChecks'];

Porqué de lo poco que se me parece que las escritas tienen que ser las mismas y necesitan de las ''.

Disculpa otra vez si puse el código errado...Pero este no inserta.
Gracias de toda forma por el esfuerzo tratando de entenderme